From 1e1ddf10e0ca1933d143308b30254e3dc77a41cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alberto=20Mart=C3=ADnez?= Date: Mon, 8 Jan 2024 15:12:17 +0100 Subject: [PATCH] 16.0[IMP]document_page: menu_parent_id context domain of menu creation --- document_page/README.rst | 1 + document_page/models/__init__.py | 1 + document_page/models/ir_ui_menu.py | 27 +++++++++++++++++++ .../wizard/document_page_create_menu.xml | 5 +++- 4 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 document_page/models/ir_ui_menu.py diff --git a/document_page/README.rst b/document_page/README.rst index 11992bb9643..ab95e4ac45d 100644 --- a/document_page/README.rst +++ b/document_page/README.rst @@ -93,6 +93,7 @@ Trobz * `Sygel `_: * Ángel García de la Chica Herrera + * Alberto Martínez Rodríguez Other credits ~~~~~~~~~~~~~ diff --git a/document_page/models/__init__.py b/document_page/models/__init__.py index aeb44abd769..2796b2fe11d 100644 --- a/document_page/models/__init__.py +++ b/document_page/models/__init__.py @@ -2,3 +2,4 @@ from . import document_page from . import document_page_history +from . import ir_ui_menu diff --git a/document_page/models/ir_ui_menu.py b/document_page/models/ir_ui_menu.py new file mode 100644 index 00000000000..076630a3ddb --- /dev/null +++ b/document_page/models/ir_ui_menu.py @@ -0,0 +1,27 @@ +# Copyright 2024 Alberto Martínez +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models + + +class IrUiMenu(models.Model): + _inherit = "ir.ui.menu" + + def _visible_menu_ids(self, debug=False): + visible_ids = super()._visible_menu_ids(debug) + if self._context.get("ir.ui.menu.authorized_list"): + # Add the authorized by groups menus that does not have an action + menus = ( + self.with_context(**{"ir.ui.menu.full_list": True}).search([]).sudo() + ) + groups = ( + self.env.user.groups_id + if not debug + else self.env.user.groups_id - self.env.ref("base.group_no_one") + ) + authorized_menus = menus.filtered( + lambda m: not m.groups_id or m.groups_id and groups + ) + authorized_folder_menus = authorized_menus.filtered(lambda m: not m.action) + visible_ids = visible_ids.union(authorized_folder_menus.ids) + return visible_ids diff --git a/document_page/wizard/document_page_create_menu.xml b/document_page/wizard/document_page_create_menu.xml index 01cb17cf1f5..545b83bfcfc 100644 --- a/document_page/wizard/document_page_create_menu.xml +++ b/document_page/wizard/document_page_create_menu.xml @@ -8,7 +8,10 @@
- +