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.

65 lines
2.4 KiB

  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # OpenERP, Open Source Management Solution
  5. # This module copyright (C) 2014 Therp BV (<http://therp.nl>).
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Affero General Public License as
  9. # published by the Free Software Foundation, either version 3 of the
  10. # License, or (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. ##############################################################################
  21. import logging
  22. from openerp.osv import orm, fields
  23. class CleanupPurgeLine(orm.AbstractModel):
  24. """ Abstract base class for the purge wizard lines """
  25. _name = 'cleanup.purge.line'
  26. _order = 'name'
  27. _columns = {
  28. 'name': fields.char('Name', size=256, readonly=True),
  29. 'purged': fields.boolean('Purged', readonly=True),
  30. }
  31. logger = logging.getLogger('openerp.addons.database_cleanup')
  32. def purge(self, cr, uid, ids, context=None):
  33. raise NotImplementedError
  34. class PurgeWizard(orm.AbstractModel):
  35. """ Abstract base class for the purge wizards """
  36. _name = 'cleanup.purge.wizard'
  37. def default_get(self, cr, uid, fields, context=None):
  38. res = super(PurgeWizard, self).default_get(
  39. cr, uid, fields, context=context)
  40. if 'purge_line_ids' in fields:
  41. res['purge_line_ids'] = self.find(cr, uid, context=None)
  42. return res
  43. def find(self, cr, uid, ids, context=None):
  44. raise NotImplementedError
  45. def purge_all(self, cr, uid, ids, context=None):
  46. line_pool = self.pool[self._columns['purge_line_ids']._obj]
  47. for wizard in self.browse(cr, uid, ids, context=context):
  48. line_pool.purge(
  49. cr, uid, [line.id for line in wizard.purge_line_ids],
  50. context=context)
  51. return True
  52. _columns = {
  53. 'name': fields.char('Name', size=64, readonly=True),
  54. }