forked from OCA/server-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpurge_menus.py
68 lines (60 loc) · 2.23 KB
/
purge_menus.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# Copyright 2014-2016 Therp BV <http://therp.nl>
# Copyright 2021 Camptocamp <https://camptocamp.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
# pylint: disable=consider-merging-classes-inherited
from odoo import _, api, fields, models
from odoo.exceptions import UserError
class CleanupPurgeLineMenu(models.TransientModel):
_inherit = "cleanup.purge.line"
_name = "cleanup.purge.line.menu"
_description = "Cleanup Purge Line Menu"
wizard_id = fields.Many2one(
"cleanup.purge.wizard.menu", "Purge Wizard", readonly=True
)
menu_id = fields.Many2one("ir.ui.menu", "Menu entry")
def purge(self):
"""Unlink menu entries upon manual confirmation."""
if self:
objs = self
else:
objs = self.env["cleanup.purge.line.menu"].browse(
self._context.get("active_ids")
)
to_unlink = objs.filtered(lambda x: not x.purged and x.menu_id)
self.logger.info("Purging menu entries: %s", to_unlink.mapped("name"))
to_unlink.mapped("menu_id").unlink()
return to_unlink.write({"purged": True})
class CleanupPurgeWizardMenu(models.TransientModel):
_inherit = "cleanup.purge.wizard"
_name = "cleanup.purge.wizard.menu"
_description = "Purge menus"
@api.model
def find(self):
"""
Search for models that cannot be instantiated.
"""
res = []
for menu in (
self.env["ir.ui.menu"]
.with_context(active_test=False)
.search([("action", "!=", False)])
):
if menu.action.type != "ir.actions.act_window":
continue
if menu.action.res_model and menu.action.res_model not in self.env:
res.append(
(
0,
0,
{
"name": menu.complete_name,
"menu_id": menu.id,
},
)
)
if not res:
raise UserError(_("No dangling menu entries found"))
return res
purge_line_ids = fields.One2many(
"cleanup.purge.line.menu", "wizard_id", "Menus to purge"
)