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.

48 lines
1.6 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 not in self.env or\
  31. menu.action.src_model not in self.env:
  32. res.append((0, 0, {
  33. 'name': menu.complete_name,
  34. 'menu_id': menu.id,
  35. }))
  36. if not res:
  37. raise UserError(_('No dangling menu entries found'))
  38. return res
  39. purge_line_ids = fields.One2many(
  40. 'cleanup.purge.line.menu', 'wizard_id', 'Menus to purge')