Merge pull request #2616 from Tecnativa/10.0-fix-web_responsive-menu_search-visibility

[10.0][FIX] web_responsive: Filter properly menus on AppDrawer search
10.0
Pedro M. Baeza 2023-09-18 16:49:14 +02:00 committed by GitHub
commit bdc2c8bf20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 0 deletions

View File

@ -1 +1,2 @@
# -*- coding: utf-8 -*-
from . import models

View File

@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
from . import ir_ui_menu

View File

@ -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

View File

@ -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]
])