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.

81 lines
3.0 KiB

  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # OpenERP, Open Source Management Solution
  5. # This module copyright (C) 2015 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. from openerp.osv import orm, fields
  22. from openerp.tools.translate import _
  23. class CleanupPurgeLineMenu(orm.TransientModel):
  24. _inherit = 'cleanup.purge.line'
  25. _name = 'cleanup.purge.line.menu'
  26. _columns = {
  27. 'wizard_id': fields.many2one(
  28. 'cleanup.purge.wizard.menu', 'Purge Wizard', readonly=True),
  29. 'menu_id': fields.many2one('ir.ui.menu', 'Menu entry'),
  30. }
  31. def purge(self, cr, uid, ids, context=None):
  32. self.pool['ir.ui.menu'].unlink(
  33. cr, uid,
  34. [this.menu_id.id for this in self.browse(cr, uid, ids,
  35. context=context)],
  36. context=context)
  37. return self.write(cr, uid, ids, {'purged': True}, context=context)
  38. class CleanupPurgeWizardMenu(orm.TransientModel):
  39. _inherit = 'cleanup.purge.wizard'
  40. _name = 'cleanup.purge.wizard.menu'
  41. def default_get(self, cr, uid, fields, context=None):
  42. res = super(CleanupPurgeWizardMenu, self).default_get(
  43. cr, uid, fields, context=context)
  44. if 'name' in fields:
  45. res['name'] = _('Purge menus')
  46. return res
  47. def find(self, cr, uid, context=None):
  48. """
  49. Search for models that cannot be instantiated.
  50. """
  51. res = []
  52. for menu in self.pool['ir.ui.menu'].browse(
  53. cr, uid, self.pool['ir.ui.menu'].search(
  54. cr, uid, [], context=dict(
  55. context or {}, active_test=False))):
  56. if not menu.action or menu.action.type != 'ir.actions.act_window':
  57. continue
  58. if not self.pool.get(menu.action.res_model):
  59. res.append((0, 0, {
  60. 'name': menu.complete_name,
  61. 'menu_id': menu.id,
  62. }))
  63. if not res:
  64. raise orm.except_orm(
  65. _('Nothing to do'),
  66. _('No dangling menu entries found'))
  67. return res
  68. _columns = {
  69. 'purge_line_ids': fields.one2many(
  70. 'cleanup.purge.line.menu',
  71. 'wizard_id', 'Menus to purge'),
  72. }