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.

106 lines
3.9 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 import api, SUPERUSER_ID
  23. from openerp.exceptions import AccessDenied
  24. from openerp.osv import orm, fields
  25. class CleanupPurgeLine(orm.AbstractModel):
  26. """ Abstract base class for the purge wizard lines """
  27. _name = 'cleanup.purge.line'
  28. _order = 'name'
  29. _columns = {
  30. 'name': fields.char('Name', size=256, readonly=True),
  31. 'purged': fields.boolean('Purged', readonly=True),
  32. }
  33. logger = logging.getLogger('openerp.addons.database_cleanup')
  34. def purge(self, cr, uid, ids, context=None):
  35. raise NotImplementedError
  36. @api.model
  37. def create(self, values):
  38. # make sure the user trying this is actually supposed to do it
  39. if self.env.uid != SUPERUSER_ID and\
  40. not self.env.ref('database_cleanup.menu_database_cleanup')\
  41. .parent_id._filter_visible_menus():
  42. raise AccessDenied
  43. return super(CleanupPurgeLine, self).create(values)
  44. class PurgeWizard(orm.AbstractModel):
  45. """ Abstract base class for the purge wizards """
  46. _name = 'cleanup.purge.wizard'
  47. def default_get(self, cr, uid, fields, context=None):
  48. res = super(PurgeWizard, self).default_get(
  49. cr, uid, fields, context=context)
  50. if 'purge_line_ids' in fields:
  51. res['purge_line_ids'] = self.find(cr, uid, context=None)
  52. return res
  53. def find(self, cr, uid, ids, context=None):
  54. raise NotImplementedError
  55. def purge_all(self, cr, uid, ids, context=None):
  56. line_pool = self.pool[self._columns['purge_line_ids']._obj]
  57. for wizard in self.browse(cr, uid, ids, context=context):
  58. line_pool.purge(
  59. cr, uid, [line.id for line in wizard.purge_line_ids],
  60. context=context)
  61. return True
  62. def get_wizard_action(self, cr, uid, context=None):
  63. wizard_id = self.create(cr, uid, {}, context=context)
  64. return {
  65. 'type': 'ir.actions.act_window',
  66. 'views': [(False, 'form')],
  67. 'res_model': self._name,
  68. 'res_id': wizard_id,
  69. 'flags': {
  70. 'action_buttons': False,
  71. 'sidebar': False,
  72. },
  73. }
  74. def select_lines(self, cr, uid, ids, context=None):
  75. return {
  76. 'type': 'ir.actions.act_window',
  77. 'name': 'Select lines to purge',
  78. 'views': [(False, 'tree'), (False, 'form')],
  79. 'res_model': self._columns['purge_line_ids']._obj,
  80. 'domain': [('wizard_id', 'in', ids)],
  81. }
  82. @api.model
  83. def create(self, values):
  84. # make sure the user trying this is actually supposed to do it
  85. if self.env.uid != SUPERUSER_ID and\
  86. not self.env.ref('database_cleanup.menu_database_cleanup')\
  87. .parent_id._filter_visible_menus():
  88. raise AccessDenied
  89. return super(PurgeWizard, self).create(values)
  90. _columns = {
  91. 'name': fields.char('Name', size=64, readonly=True),
  92. }