From 53c0edfe059daffd3bb7f022c24e3823468bcfda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Wed, 17 Apr 2024 20:23:26 +0200 Subject: [PATCH] Use a set of models to compute cache key for record rules --- modules/attendance/ir.py | 6 +++--- modules/company/ir.py | 4 ++-- modules/purchase_requisition/ir.py | 6 +++--- modules/timesheet/ir.py | 6 +++--- trytond/trytond/ir/rule.py | 6 ++---- trytond/trytond/res/ir.py | 6 +++--- 6 files changed, 16 insertions(+), 18 deletions(-) diff --git a/modules/attendance/ir.py b/modules/attendance/ir.py index affbe3137e..f716324396 100644 --- a/modules/attendance/ir.py +++ b/modules/attendance/ir.py @@ -20,10 +20,10 @@ class Rule(metaclass=PoolMeta): return context @classmethod - def _get_cache_key(cls, model_name): + def _get_cache_key(cls, model_names): pool = Pool() User = pool.get('res.user') - key = super()._get_cache_key(model_name) - if model_name in _EMPLOYEES_RULE_MODELS: + key = super()._get_cache_key(model_names) + if model_names & _EMPLOYEES_RULE_MODELS: key = (*key, User.get_employees()) return key diff --git a/modules/company/ir.py b/modules/company/ir.py index 5813750d96..d640baf496 100644 --- a/modules/company/ir.py +++ b/modules/company/ir.py @@ -53,10 +53,10 @@ class Rule(metaclass=PoolMeta): '\n- "companies" as list of ids from the current user') @classmethod - def _get_cache_key(cls, model_name): + def _get_cache_key(cls, model_names): pool = Pool() User = pool.get('res.user') - key = super()._get_cache_key(model_name) + key = super()._get_cache_key(model_names) return (*key, User.get_companies()) @classmethod diff --git a/modules/purchase_requisition/ir.py b/modules/purchase_requisition/ir.py index baad2791c2..23a7308ea8 100644 --- a/modules/purchase_requisition/ir.py +++ b/modules/purchase_requisition/ir.py @@ -17,10 +17,10 @@ class Rule(metaclass=PoolMeta): return context @classmethod - def _get_cache_key(cls, model_name): + def _get_cache_key(cls, model_names): pool = Pool() User = pool.get('res.user') - key = super()._get_cache_key(model_name) - if model_name == 'purchase.requisition': + key = super()._get_cache_key(model_names) + if 'purchase.requisition' in model_names: key = (*key, User.get_employees()) return key diff --git a/modules/timesheet/ir.py b/modules/timesheet/ir.py index 1a96e56171..4073ad7cdd 100644 --- a/modules/timesheet/ir.py +++ b/modules/timesheet/ir.py @@ -24,10 +24,10 @@ class Rule(metaclass=PoolMeta): return context @classmethod - def _get_cache_key(cls, model_name): + def _get_cache_key(cls, model_names): pool = Pool() User = pool.get('res.user') - key = super()._get_cache_key(model_name) - if model_name in _EMPLOYEES_RULE_MODELS: + key = super()._get_cache_key(model_names) + if model_names & _EMPLOYEES_RULE_MODELS: key = (*key, User.get_employees()) return key diff --git a/trytond/trytond/ir/rule.py b/trytond/trytond/ir/rule.py index eea14c71d8..6d670d872c 100644 --- a/trytond/trytond/ir/rule.py +++ b/trytond/trytond/ir/rule.py @@ -203,7 +203,7 @@ class Rule(ModelSQL, ModelView): } @classmethod - def _get_cache_key(cls, model_name): + def _get_cache_key(cls, model_names): pool = Pool() User = pool.get('res.user') # _datetime value will be added to the domain @@ -294,9 +294,7 @@ class Rule(ModelSQL, ModelView): model_names, _ = _get_access_models(pool.get(model_name)) - key = (model_name, mode) - for m_name in sorted(model_names): - key += cls._get_cache_key(m_name) + key = (model_name, mode) + cls._get_cache_key(model_names) domain = cls._domain_get_cache.get(key, False) if domain is not False: return domain diff --git a/trytond/trytond/res/ir.py b/trytond/trytond/res/ir.py index eed0e70e64..a17bcc98cb 100644 --- a/trytond/trytond/res/ir.py +++ b/trytond/trytond/res/ir.py @@ -220,9 +220,9 @@ class Rule(metaclass=PoolMeta): return context @classmethod - def _get_cache_key(cls, model_name): - key = super()._get_cache_key(model_name) - if model_name in {'res.user.warning', 'res.user.application'}: + def _get_cache_key(cls, model_names): + key = super()._get_cache_key(model_names) + if model_names & {'res.user.warning', 'res.user.application'}: key = (*key, Transaction().user) return key