mirror of
https://github.com/OCA/knowledge.git
synced 2025-07-14 01:41:26 -06:00
16.0[IMP]document_page: menu_parent_id context domain of menu creation
This commit is contained in:
parent
613e102b11
commit
17d246f7e4
@ -93,6 +93,7 @@ Trobz
|
|||||||
* `Sygel <https://www.sygel.es>`_:
|
* `Sygel <https://www.sygel.es>`_:
|
||||||
|
|
||||||
* Ángel García de la Chica Herrera
|
* Ángel García de la Chica Herrera
|
||||||
|
* Alberto Martínez Rodríguez
|
||||||
|
|
||||||
Other credits
|
Other credits
|
||||||
~~~~~~~~~~~~~
|
~~~~~~~~~~~~~
|
||||||
|
@ -2,3 +2,4 @@
|
|||||||
|
|
||||||
from . import document_page
|
from . import document_page
|
||||||
from . import document_page_history
|
from . import document_page_history
|
||||||
|
from . import ir_ui_menu
|
||||||
|
27
document_page/models/ir_ui_menu.py
Normal file
27
document_page/models/ir_ui_menu.py
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
# Copyright 2024 Alberto Martínez <alberto.martinez@sygel.es>
|
||||||
|
# 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
|
@ -27,3 +27,17 @@ class TestDocumentPageCreateMenu(common.TransactionCase):
|
|||||||
).default_get(fields_list)
|
).default_get(fields_list)
|
||||||
|
|
||||||
self.assertEqual(res["menu_name"], "Odoo 15.0 Functional Demo")
|
self.assertEqual(res["menu_name"], "Odoo 15.0 Functional Demo")
|
||||||
|
|
||||||
|
def test_page_menu_parent_id_context(self):
|
||||||
|
"""Test page menu parent_id context."""
|
||||||
|
menu_parent = self.env["ir.ui.menu"].create({"name": "Test Folder Menu"})
|
||||||
|
context_results = (
|
||||||
|
self.env["ir.ui.menu"]
|
||||||
|
.with_context(**{"ir.ui.menu.authorized_list": True})
|
||||||
|
.search([("id", "=", menu_parent.id)])
|
||||||
|
)
|
||||||
|
no_context_results = self.env["ir.ui.menu"].search(
|
||||||
|
[("id", "=", menu_parent.id)]
|
||||||
|
)
|
||||||
|
self.assertEqual(context_results[:1].id, menu_parent.id)
|
||||||
|
self.assertEqual(any(no_context_results), False)
|
||||||
|
@ -8,7 +8,10 @@
|
|||||||
<form>
|
<form>
|
||||||
<group string="Menu Information">
|
<group string="Menu Information">
|
||||||
<field name="menu_name" />
|
<field name="menu_name" />
|
||||||
<field name="menu_parent_id" />
|
<field
|
||||||
|
name="menu_parent_id"
|
||||||
|
context="{'ir.ui.menu.authorized_list': True}"
|
||||||
|
/>
|
||||||
</group>
|
</group>
|
||||||
<footer>
|
<footer>
|
||||||
<button
|
<button
|
||||||
|
Loading…
Reference in New Issue
Block a user