From 6269ed0f45a3dcfd2991379a53cb8eeb82650524 Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Sat, 16 Sep 2023 13:01:27 +0200 Subject: [PATCH] [FIX] web_responsive: Filter properly menus on AppDrawer search The filtering that is done on the menus by upstream doesn't take into account the visibility of their ancestors to decide if the menu is visible or not, which is needed for the AppDrawer menu search. TT45078 --- web_responsive/__init__.py | 1 + web_responsive/models/__init__.py | 2 ++ web_responsive/models/ir_ui_menu.py | 31 +++++++++++++++++++ .../static/src/js/web_responsive.js | 1 + 4 files changed, 35 insertions(+) create mode 100644 web_responsive/models/__init__.py create mode 100644 web_responsive/models/ir_ui_menu.py diff --git a/web_responsive/__init__.py b/web_responsive/__init__.py index 40a96afc6..a0fdc10fe 100644 --- a/web_responsive/__init__.py +++ b/web_responsive/__init__.py @@ -1 +1,2 @@ # -*- coding: utf-8 -*- +from . import models diff --git a/web_responsive/models/__init__.py b/web_responsive/models/__init__.py new file mode 100644 index 000000000..5a7a21a99 --- /dev/null +++ b/web_responsive/models/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf-8 -*- +from . import ir_ui_menu diff --git a/web_responsive/models/ir_ui_menu.py b/web_responsive/models/ir_ui_menu.py new file mode 100644 index 000000000..338069fba --- /dev/null +++ b/web_responsive/models/ir_ui_menu.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +from odoo import api, models + + +class IrUiMenu(models.Model): + _inherit = 'ir.ui.menu' + + @api.model + def search(self, args, offset=0, limit=None, order=None, count=False): + """The filtering that is done on the menus by upstream doesn't take into account + the visibility of their ancestors to decide if the menu is visible or not, which + is needed for the AppDrawer menu search. + """ + menus = super(IrUiMenu, self).search( + args, offset=offset, limit=limit, order=order, count=count + ) + if menus and not count and self.env.context.get("responsive_search"): + accesible_menus = self.env["ir.ui.menu"] + full_menus = self.with_context(responsive_search=False).search([]) + for menu in menus: + add = True + parent_menu = menu.parent_id + while parent_menu: + if parent_menu not in full_menus: + add = False + break + parent_menu = parent_menu.parent_id + if add: + accesible_menus += menu + menus = accesible_menus + return menus diff --git a/web_responsive/static/src/js/web_responsive.js b/web_responsive/static/src/js/web_responsive.js index 075b47a7e..976d0653e 100644 --- a/web_responsive/static/src/js/web_responsive.js +++ b/web_responsive/static/src/js/web_responsive.js @@ -314,6 +314,7 @@ odoo.define('web_responsive', function(require) { this.$searchInput = $('#appDrawerSearchInput').focus(); var Menus = new DataModel('ir.ui.menu'); Menus.query(['action', 'display_name', 'id']) + .context({"responsive_search": true}) .filter([['name', 'ilike', this.$searchInput.val()], ['action', '!=', false] ])