File tree 5 files changed +47
-1
lines changed
5 files changed +47
-1
lines changed Original file line number Diff line number Diff line change 93
93
* `Sygel <https://www.sygel.es >`_:
94
94
95
95
* Ángel García de la Chica Herrera
96
+ * Alberto Martínez Rodríguez
96
97
97
98
Other credits
98
99
~~~~~~~~~~~~~
Original file line number Diff line number Diff line change 2
2
3
3
from . import document_page
4
4
from . import document_page_history
5
+ from . import ir_ui_menu
Original file line number Diff line number Diff line change
1
+ # Copyright 2024 Alberto Martínez <alberto.martinez@sygel.es>
2
+ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
3
+
4
+ from odoo import models
5
+
6
+
7
+ class IrUiMenu (models .Model ):
8
+ _inherit = "ir.ui.menu"
9
+
10
+ def _visible_menu_ids (self , debug = False ):
11
+ visible_ids = super ()._visible_menu_ids (debug )
12
+ if self ._context .get ("ir.ui.menu.authorized_list" ):
13
+ # Add the authorized by groups menus that does not have an action
14
+ menus = (
15
+ self .with_context (** {"ir.ui.menu.full_list" : True }).search ([]).sudo ()
16
+ )
17
+ groups = (
18
+ self .env .user .groups_id
19
+ if not debug
20
+ else self .env .user .groups_id - self .env .ref ("base.group_no_one" )
21
+ )
22
+ authorized_menus = menus .filtered (
23
+ lambda m : not m .groups_id or m .groups_id and groups
24
+ )
25
+ authorized_folder_menus = authorized_menus .filtered (lambda m : not m .action )
26
+ visible_ids = visible_ids .union (authorized_folder_menus .ids )
27
+ return visible_ids
Original file line number Diff line number Diff line change @@ -27,3 +27,17 @@ def test_page_menu_creation(self):
27
27
).default_get (fields_list )
28
28
29
29
self .assertEqual (res ["menu_name" ], "Odoo 15.0 Functional Demo" )
30
+
31
+ def test_page_menu_parent_id_context (self ):
32
+ """Test page menu parent_id context."""
33
+ menu_parent = self .env ["ir.ui.menu" ].create ({"name" : "Test Folder Menu" })
34
+ context_results = (
35
+ self .env ["ir.ui.menu" ]
36
+ .with_context (** {"ir.ui.menu.authorized_list" : True })
37
+ .search ([("id" , "=" , menu_parent .id )])
38
+ )
39
+ no_context_results = self .env ["ir.ui.menu" ].search (
40
+ [("id" , "=" , menu_parent .id )]
41
+ )
42
+ self .assertEqual (context_results [:1 ].id , menu_parent .id )
43
+ self .assertEqual (any (no_context_results ), False )
Original file line number Diff line number Diff line change 8
8
<form >
9
9
<group string =" Menu Information" >
10
10
<field name =" menu_name" />
11
- <field name =" menu_parent_id" />
11
+ <field
12
+ name =" menu_parent_id"
13
+ context =" {'ir.ui.menu.authorized_list': True}"
14
+ />
12
15
</group >
13
16
<footer >
14
17
<button
You can’t perform that action at this time.
0 commit comments