The website frontend apps menu list is not working when the user has a `Home Action` defined on his user. The `Home Action` is meant to redirect to the defined action whenever that user is login in. But since the backend menu links on the website have most of the time no `action` defined but just a `menu_id` defined, the `Home Action` will kick in and take over the redirection, the same way as if the user just type `/web` without any params. To solve that, we simply force the `action` of those links (if they don't already have one). This will make sure that the redirect is working as it should for users having a `Home Action` set. Step to reproduce: - Set a Home Action for any user, like "Contacts" - Go to the website frontend, eg on `/`. - Click on the top left button to show the backend app menus list - Click on any menu (CRM, Invoicing, Calendar..) -> Most of those menu will not redirect you were you are supposed to be but on your Home Action instead. You can figure which one will be buggy or not by just mouseovering the link and see if the URL param `action` is set to something or not. --- Technical hints --- There is multiple methods to get the list of menus in Odoo: - `load_web_menus`: called by the web client rpc, calling `load_menus`. If a top/app menu has no action defined on it, it sets the first found action of their children menus to it. It returns the full (flat) list of menus, not only the top/app ones. This method is not ormcached but is calling an ormcached method and just doing some tiny work on the data. - `load_menus_root`: called only by website backend template to add the app list on the website (in the frontend) to jump to the backend. It does not force the action if a menu has no action set on it. It returns only the top/app menus. This method is ormcached. Note that this method seems only used by the website module. - `load_menus`: returns the full (flat) list of menus without a force action This method is ormcached. Fixes https://github.com/odoo/odoo/issues/119971 task-3378963 closes odoo/odoo#127840 X-original-commit: f28a349aa40b2ea48ef8f2b71e806b965777014f Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com> Signed-off-by: Romain Derie (rde) <rde@odoo.com>
27 lines
955 B
Python
27 lines
955 B
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo import api, models, tools
|
|
from odoo.http import request
|
|
|
|
|
|
class IrUiMenu(models.Model):
|
|
_inherit = 'ir.ui.menu'
|
|
|
|
@api.model
|
|
@tools.ormcache_context('self._uid', keys=('lang', 'force_action',))
|
|
def load_menus_root(self):
|
|
root_menus = super().load_menus_root()
|
|
if self.env.context.get('force_action'):
|
|
web_menus = self.load_web_menus(request.session.debug if request else False)
|
|
for menu in root_menus['children']:
|
|
# Force the action.
|
|
if (
|
|
not menu['action']
|
|
and web_menus[menu['id']]['actionModel']
|
|
and web_menus[menu['id']]['actionID']
|
|
):
|
|
menu['action'] = f"{web_menus[menu['id']]['actionModel']},{web_menus[menu['id']]['actionID']}"
|
|
|
|
return root_menus
|