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.

58 lines
2.1 KiB

  1. # Copyright 2014-2016 Therp BV <http://therp.nl>
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  3. # pylint: disable=consider-merging-classes-inherited
  4. from odoo import _, api, fields, models
  5. from odoo.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. """Unlink menu entries upon manual confirmation."""
  15. if self:
  16. objs = self
  17. else:
  18. objs = self.env['cleanup.purge.line.menu']\
  19. .browse(self._context.get('active_ids'))
  20. to_unlink = objs.filtered(lambda x: not x.purged and x.menu_id)
  21. self.logger.info('Purging menu entries: %s', to_unlink.mapped('name'))
  22. to_unlink.mapped('menu_id').unlink()
  23. return to_unlink.write({'purged': True})
  24. class CleanupPurgeWizardMenu(models.TransientModel):
  25. _inherit = 'cleanup.purge.wizard'
  26. _name = 'cleanup.purge.wizard.menu'
  27. _description = 'Purge menus'
  28. @api.model
  29. def find(self):
  30. """
  31. Search for models that cannot be instantiated.
  32. """
  33. res = []
  34. for menu in self.env['ir.ui.menu'].with_context(active_test=False)\
  35. .search([('action', '!=', False)]):
  36. if menu.action.type != 'ir.actions.act_window':
  37. continue
  38. if (menu.action.res_model and menu.action.res_model not in
  39. self.env) or \
  40. (menu.action.src_model and menu.action.src_model not in
  41. self.env):
  42. res.append((0, 0, {
  43. 'name': menu.complete_name,
  44. 'menu_id': menu.id,
  45. }))
  46. if not res:
  47. raise UserError(_('No dangling menu entries found'))
  48. return res
  49. purge_line_ids = fields.One2many(
  50. 'cleanup.purge.line.menu', 'wizard_id', 'Menus to purge')