diff --git a/portal_backend/models/ir_ui_menu.py b/portal_backend/models/ir_ui_menu.py index 2ef6ecb1..80fd78fd 100644 --- a/portal_backend/models/ir_ui_menu.py +++ b/portal_backend/models/ir_ui_menu.py @@ -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)]} + )