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.

50 lines
1.7 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2014-2016 Therp BV <http://therp.nl>
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from openerp import _, api, fields, models
  5. from openerp.exceptions import UserError
  6. class CleanupPurgeLineMenu(models.TransientModel):
  7. _inherit = 'cleanup.purge.line'
  8. _name = 'cleanup.purge.line.menu'
  9. wizard_id = fields.Many2one(
  10. 'cleanup.purge.wizard.menu', 'Purge Wizard', readonly=True)
  11. menu_id = fields.Many2one('ir.ui.menu', 'Menu entry')
  12. @api.multi
  13. def purge(self):
  14. self.mapped('menu_id').unlink()
  15. return self.write({'purged': True})
  16. class CleanupPurgeWizardMenu(models.TransientModel):
  17. _inherit = 'cleanup.purge.wizard'
  18. _name = 'cleanup.purge.wizard.menu'
  19. _description = 'Purge menus'
  20. @api.model
  21. def find(self):
  22. """
  23. Search for models that cannot be instantiated.
  24. """
  25. res = []
  26. for menu in self.env['ir.ui.menu'].with_context(active_test=False)\
  27. .search([('action', '!=', False)]):
  28. if menu.action.type != 'ir.actions.act_window':
  29. continue
  30. if (menu.action.res_model and menu.action.res_model not in
  31. self.env) or \
  32. (menu.action.src_model and menu.action.src_model not in
  33. self.env):
  34. res.append((0, 0, {
  35. 'name': menu.complete_name,
  36. 'menu_id': menu.id,
  37. }))
  38. if not res:
  39. raise UserError(_('No dangling menu entries found'))
  40. return res
  41. purge_line_ids = fields.One2many(
  42. 'cleanup.purge.line.menu', 'wizard_id', 'Menus to purge')