changeset 28eda5aede81 in trytond:5.0
details: https://hg.tryton.org/trytond?cmd=changeset&node=28eda5aede81
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 c4afc44694c3 -r 28eda5aede81 trytond/ir/ui/menu.py
--- a/trytond/ir/ui/menu.py     Sat Apr 24 19:27:07 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 (
@@ -166,19 +167,21 @@
         action_keywords.sort(key=key)
         for type, action_keywords in groupby(action_keywords, key=key):
             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

Reply via email to