changeset eacff915c0f4 in trytond:5.8
details: https://hg.tryton.org/trytond?cmd=changeset&node=eacff915c0f4
description:
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
(grafted from 5dde2220350cc8739b572b183d304fca385931a5)
diffstat:
trytond/ir/ui/menu.py | 11 +++++++----
1 files changed, 7 insertions(+), 4 deletions(-)
diffs (36 lines):
diff -r 42c87dc09c2e -r eacff915c0f4 trytond/ir/ui/menu.py
--- a/trytond/ir/ui/menu.py Wed Apr 21 23:54:43 2021 +0200
+++ b/trytond/ir/ui/menu.py Fri Aug 27 08:44:56 2021 +0200
@@ -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 (
@@ -164,19 +165,21 @@
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