From 6dd98fac4a3b752ba6acd601f30631028e697af7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Fri, 27 Aug 2021 08:44:56 +0200 Subject: [PATCH] Use a list to store multiple keywords of an action When computing the action of a menu, if multiple menus have the same action only the first one will get the right value. The others get the default value because the dictionary action2keyword store only the last keyword. issue10659 review353801002 --- trytond/ir/ui/menu.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/trytond/ir/ui/menu.py b/trytond/ir/ui/menu.py index 08616d1e5f..43fd0e5176 100644 --- a/trytond/ir/ui/menu.py +++ b/trytond/ir/ui/menu.py @@ -1,5 +1,6 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. +from collections import defaultdict from itertools import groupby from trytond.model import ( @@ -167,19 +168,21 @@ class UIMenu( action_keywords.sort(key=action_type) for type, action_keywords in groupby(action_keywords, key=action_type): action_keywords = list(action_keywords) + action2keywords = defaultdict(list) for action_keyword in action_keywords: model = action_keyword.model actions[model.id] = '%s,-1' % type + action2keywords[action_keyword.action.id].append( + action_keyword) Action = pool.get(type) - action2keyword = {k.action.id: k for k in action_keywords} with Transaction().set_context(active_test=False): factions = Action.search([ - ('action', 'in', list(action2keyword.keys())), + ('action', 'in', list(action2keywords.keys())), ]) for action in factions: - model = action2keyword[action.id].model - actions[model.id] = str(action) + for action_keyword in action2keywords[action.id]: + actions[action_keyword.model.id] = str(action) return actions @classmethod