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
This commit is contained in:
Cédric Krier committed 2021-08-27 08:44:56 +02:00
1 parent fb9238b8bf
commit 6dd98fac4a
1 file changed
+7 -4
+7 -4
View File
@@ -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