-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathir_module_module.py
More file actions
103 lines (94 loc) · 3.52 KB
/
Copy pathir_module_module.py
File metadata and controls
103 lines (94 loc) · 3.52 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import logging
from odoo import models
_logger = logging.getLogger(__name__)
class IrModuleModule(models.Model):
_inherit = "ir.module.module"
# Map module technical names to menu xml_ids and icon paths
MENU_APP = {
"project_todo": {
"menu_xml_id": "project_todo.menu_todo_todos",
},
"mail": {
"menu_xml_id": "mail.menu_root_discuss",
},
"spreadsheet_dashboard": {
"menu_xml_id": "spreadsheet_dashboard.spreadsheet_dashboard_menu_root",
},
"project": {
"menu_xml_id": "project.menu_main_pm",
},
"mass_mailing": {
"menu_xml_id": "mass_mailing.mass_mailing_menu_root",
},
"survey": {
"menu_xml_id": "survey.menu_surveys",
},
"hr": {
"menu_xml_id": "hr.menu_hr_root",
},
"calendar": {
"menu_xml_id": "calendar.mail_menu_calendar",
},
"contacts": {
"menu_xml_id": "contacts.menu_contacts",
},
"account": {
"menu_xml_id": "account.menu_finance",
},
"event": {
"menu_xml_id": "event.event_main_menu",
},
"stock": {
"menu_xml_id": "stock.menu_stock_root",
},
"utm": {
"menu_xml_id": "utm.menu_link_tracker_root",
},
"fastapi": {
"menu_xml_id": "fastapi.menu_fastapi_root",
},
"job_worker": {
"menu_xml_id": "job_worker.menu_queue_job_root",
},
}
def hide_menus(self):
for module in self.search([]):
menu_info = self.MENU_APP.get(module.name)
if menu_info:
try:
menu = self.env.ref(menu_info["menu_xml_id"])
except ValueError:
_logger.debug("Menu XML ID not found: %s", menu_info["menu_xml_id"])
menu = False
if menu:
hidden_menus = self.env["spp.hide.menu"].search([("menu_id", "=", menu.id)])
if not hidden_menus:
hidden_menu = self.env["spp.hide.menu"].create(
{
"menu_id": menu.id,
"xml_id": menu_info["menu_xml_id"],
}
)
hidden_menu.hide_menu()
elif hidden_menus.state == "show":
hidden_menus.hide_menu()
elif hidden_menus.state == "hide":
# Module upgrade may have reset group_ids via XML
# (noupdate="0"). Re-apply hiding if stale.
hidden_menus._reapply_hide()
def next(self):
# Call your menu hiding logic first
self.hide_menus()
# Then call the original Odoo logic
return super().next()
def _register_hook(self):
# next() only runs on the immediate install/upgrade path
# (button_immediate_*). Upgrades through the base.module.upgrade
# wizard or the CLI (-u) reload menu XML — resetting group_ids via
# noupdate="0" — but never call next(), leaving hidden menus visible.
# _register_hook runs at the end of every registry load (startup,
# install, upgrade — all paths), so re-applying hiding here keeps
# menus hidden regardless of how the upgrade was triggered.
res = super()._register_hook()
self.hide_menus()
return res