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.

87 lines
3.1 KiB

11 years ago
  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. def get_wizard_action(self, cr, uid, context=None):
  53. wizard_id = self.create(cr, uid, {}, context=context)
  54. return {
  55. 'type': 'ir.actions.act_window',
  56. 'views': [(False, 'form')],
  57. 'res_model': self._name,
  58. 'res_id': wizard_id,
  59. 'flags': {
  60. 'action_buttons': False,
  61. 'sidebar': False,
  62. },
  63. }
  64. def select_lines(self, cr, uid, ids, context=None):
  65. return {
  66. 'type': 'ir.actions.act_window',
  67. 'name': 'Select lines to purge',
  68. 'views': [(False, 'tree'), (False, 'form')],
  69. 'res_model': self._columns['purge_line_ids']._obj,
  70. 'domain': [('wizard_id', 'in', ids)],
  71. }
  72. _columns = {
  73. 'name': fields.char('Name', size=64, readonly=True),
  74. }