You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
2.9 KiB

  1. # Copyright 2014-2016 Therp BV <http://therp.nl>
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  3. # pylint: disable=consider-merging-classes-inherited
  4. import logging
  5. from odoo import _, api, fields, models
  6. from odoo.exceptions import AccessDenied
  7. class CleanupPurgeLine(models.AbstractModel):
  8. """ Abstract base class for the purge wizard lines """
  9. _name = 'cleanup.purge.line'
  10. _order = 'name'
  11. _description = 'Purge Column Abstract Wizard'
  12. name = fields.Char('Name', readonly=True)
  13. purged = fields.Boolean('Purged', readonly=True)
  14. wizard_id = fields.Many2one('cleanup.purge.wizard')
  15. logger = logging.getLogger('odoo.addons.database_cleanup')
  16. @api.multi
  17. def purge(self):
  18. raise NotImplementedError
  19. @api.model
  20. def create(self, values):
  21. # make sure the user trying this is actually supposed to do it
  22. if self.env.ref(
  23. 'base.group_erp_manager') not in self.env.user.groups_id:
  24. raise AccessDenied
  25. return super(CleanupPurgeLine, self).create(values)
  26. class PurgeWizard(models.AbstractModel):
  27. """ Abstract base class for the purge wizards """
  28. _name = 'cleanup.purge.wizard'
  29. _description = 'Purge stuff'
  30. @api.model
  31. def default_get(self, fields_list):
  32. res = super(PurgeWizard, self).default_get(fields_list)
  33. if 'purge_line_ids' in fields_list:
  34. res['purge_line_ids'] = self.find()
  35. return res
  36. @api.multi
  37. def find(self):
  38. raise NotImplementedError
  39. @api.multi
  40. def purge_all(self):
  41. self.mapped('purge_line_ids').purge()
  42. return True
  43. @api.model
  44. def get_wizard_action(self):
  45. wizard = self.create({})
  46. return {
  47. 'type': 'ir.actions.act_window',
  48. 'name': wizard.display_name,
  49. 'views': [(False, 'form')],
  50. 'res_model': self._name,
  51. 'res_id': wizard.id,
  52. 'flags': {
  53. 'action_buttons': False,
  54. 'sidebar': False,
  55. },
  56. }
  57. @api.multi
  58. def select_lines(self):
  59. return {
  60. 'type': 'ir.actions.act_window',
  61. 'name': _('Select lines to purge'),
  62. 'views': [(False, 'tree'), (False, 'form')],
  63. 'res_model': self._fields['purge_line_ids'].comodel_name,
  64. 'domain': [('wizard_id', 'in', self.ids)],
  65. }
  66. @api.multi
  67. def name_get(self):
  68. return [
  69. (this.id, self._description)
  70. for this in self
  71. ]
  72. @api.model
  73. def create(self, values):
  74. # make sure the user trying this is actually supposed to do it
  75. if self.env.ref(
  76. 'base.group_erp_manager') not in self.env.user.groups_id:
  77. raise AccessDenied
  78. return super(PurgeWizard, self).create(values)
  79. purge_line_ids = fields.One2many('cleanup.purge.line', 'wizard_id')