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.

95 lines
2.8 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. name = fields.Char('Name', readonly=True)
  12. purged = fields.Boolean('Purged', readonly=True)
  13. wizard_id = fields.Many2one('cleanup.purge.wizard')
  14. logger = logging.getLogger('odoo.addons.database_cleanup')
  15. @api.multi
  16. def purge(self):
  17. raise NotImplementedError
  18. @api.model
  19. def create(self, values):
  20. # make sure the user trying this is actually supposed to do it
  21. if self.env.ref(
  22. 'base.group_erp_manager') not in self.env.user.groups_id:
  23. raise AccessDenied
  24. return super(CleanupPurgeLine, self).create(values)
  25. class PurgeWizard(models.AbstractModel):
  26. """ Abstract base class for the purge wizards """
  27. _name = 'cleanup.purge.wizard'
  28. _description = 'Purge stuff'
  29. @api.model
  30. def default_get(self, fields_list):
  31. res = super(PurgeWizard, self).default_get(fields_list)
  32. if 'purge_line_ids' in fields_list:
  33. res['purge_line_ids'] = self.find()
  34. return res
  35. @api.multi
  36. def find(self):
  37. raise NotImplementedError
  38. @api.multi
  39. def purge_all(self):
  40. self.mapped('purge_line_ids').purge()
  41. return True
  42. @api.model
  43. def get_wizard_action(self):
  44. wizard = self.create({})
  45. return {
  46. 'type': 'ir.actions.act_window',
  47. 'name': wizard.display_name,
  48. 'views': [(False, 'form')],
  49. 'res_model': self._name,
  50. 'res_id': wizard.id,
  51. 'flags': {
  52. 'action_buttons': False,
  53. 'sidebar': False,
  54. },
  55. }
  56. @api.multi
  57. def select_lines(self):
  58. return {
  59. 'type': 'ir.actions.act_window',
  60. 'name': _('Select lines to purge'),
  61. 'views': [(False, 'tree'), (False, 'form')],
  62. 'res_model': self._fields['purge_line_ids'].comodel_name,
  63. 'domain': [('wizard_id', 'in', self.ids)],
  64. }
  65. @api.multi
  66. def name_get(self):
  67. return [
  68. (this.id, self._description)
  69. for this in self
  70. ]
  71. @api.model
  72. def create(self, values):
  73. # make sure the user trying this is actually supposed to do it
  74. if self.env.ref(
  75. 'base.group_erp_manager') not in self.env.user.groups_id:
  76. raise AccessDenied
  77. return super(PurgeWizard, self).create(values)
  78. purge_line_ids = fields.One2many('cleanup.purge.line', 'wizard_id')