Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions portal_backend/models/ir_ui_menu.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
from odoo import Command, api, models, tools
from odoo import Command, models


class IrUiMenu(models.Model):
_inherit = "ir.ui.menu"

@api.model
@tools.ormcache("self.env.uid", "debug", "self.env.lang")
def load_menus(self, debug):
"""Assert all parent menus has internal group."""
# NOTE:
# It is important to do it here to capture the case when portal_backend is already installed and the user
# installs another module with a parent menu without internal group.
def _register_hook(self):
"""Assert all parent menus have internal group.

NOTE:
It is done on registry load to capture the case when portal_backend is already installed and the user
installs another module with a parent menu without internal group.
It can not be done while loading the menus: that route is readonly, so writing there breaks its cursor
with "cannot execute INSERT in a read-only transaction" (the request is retried with a read/write one,
but the failed query is already logged as an error).
"""
super()._register_hook()
parent_menus_wo_group = self.sudo().search([("parent_id", "=", False), ("group_ids", "=", False)])
parent_menus_wo_group.with_context(from_config=True).write(
{"group_ids": [Command.link(self.env.ref("base.group_user").id)]}
)
return super().load_menus(debug=debug)
if parent_menus_wo_group:
parent_menus_wo_group.with_context(from_config=True).write(
{"group_ids": [Command.link(self.env.ref("base.group_user").id)]}
)
Loading