From 59d3974652c1f141b24567d81f8b87e7acd052da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20=C3=89vrard?= Date: Wed, 24 Apr 2024 21:21:28 +0200 Subject: [PATCH] Fetch name of wizards without a model [PREVIEW] Fix PCLAS-770 --- trytond/trytond/ir/action.py | 51 ++++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 8 deletions(-) diff --git a/trytond/trytond/ir/action.py b/trytond/trytond/ir/action.py index 16daa57e82c..5b230c5c4c1 100644 --- a/trytond/trytond/ir/action.py +++ b/trytond/trytond/ir/action.py @@ -1108,33 +1108,68 @@ class ActionWizard(ActionMixin, ModelSQL, ModelView): wiz_name = fields.Char('Wizard name', required=True) model = fields.Char('Model') window = fields.Boolean('Window', help='Run wizard in a new window.') + _get_name_cache = Cache('ir_action_wizard.get_name') + _get_models_cache = Cache('ir_action_wizard.get_models') @staticmethod def default_type(): return 'ir.action.wizard' + @classmethod + def create(cls, vlist): + cls._get_name_cache.clear() + cls._get_models_cache.clear() + return super().create(vlist) + + @classmethod + def write(cls, records, values, *args): + cls._get_name_cache.clear() + cls._get_models_cache.clear() + super().write(records, values, *args) + + @classmethod + def delete(cls, records): + cls._get_name_cache.clear() + cls._get_models_cache.clear() + super().delete(records) + @classmethod def get_models(cls, name, action_id=None): - # TODO add cache + key = (name, action_id) + models = cls._get_models_cache.get(key) + if models is not None: + return models + domain = [ (cls._action_name, '=', name), ] if action_id: domain.append(('id', '=', action_id)) actions = cls.search(domain) - return {a.model for a in actions if a.model} + models = {a.model for a in actions if a.model} + cls._get_models_cache.set(key, models) + return models @classmethod def get_name(cls, name, model): - # TODO add cache + key = (Transaction().language, name, model) + wiz_name = cls._get_name_cache.get(key) + if wiz_name is not None: + return wiz_name + else: + wiz_name = name + actions = cls.search([ (cls._action_name, '=', name), - ('model', '=', model), - ], limit=1) + ['OR', + ('model', '=', model), + ('model', '=', None), + ], + ], order=[('model', 'ASC NULLS LAST')]) if actions: - action, = actions - return action.name - return name + wiz_name = actions[0].name + cls._get_name_cache.set(key, wiz_name) + return wiz_name class ActionURL(ActionMixin, ModelSQL, ModelView):