From 4ac76059c8fd0f467121dd93bcb084c82a8d23f5 Mon Sep 17 00:00:00 2001 From: Sergi Almacellas Abellana Date: Fri, 2 Oct 2015 08:56:51 +0200 Subject: [PATCH] Add company from context on ir rule domain cache key issue5000 review15671002 --- __init__.py | 1 + company.py | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/__init__.py b/__init__.py index b4dfb4034a..35734648fd 100644 --- a/__init__.py +++ b/__init__.py @@ -21,6 +21,7 @@ def register(): Cron, CronCompany, PartyConfiguration, + Rule, module='company', type_='model') Pool.register( CompanyConfig, diff --git a/company.py b/company.py index 275f36eabb..4fb2278697 100644 --- a/company.py +++ b/company.py @@ -20,7 +20,7 @@ CursorInterface.cache_keys.update({'company', 'employee'}) __all__ = ['Company', 'Employee', 'UserEmployee', 'User', 'Property', 'Sequence', 'SequenceStrict', 'Date', 'CompanyConfigStart', - 'CompanyConfig', 'CompanyReport', 'LetterReport'] + 'CompanyConfig', 'CompanyReport', 'LetterReport', 'Rule'] __metaclass__ = PoolMeta @@ -249,6 +249,14 @@ class User: values['employee'] = employee_id return result + @classmethod + def write(cls, *args): + pool = Pool() + Rule = pool.get('ir.rule') + super(User, cls).write(*args) + # Restart the cache on the domain_get method + Rule._domain_get_cache.clear() + class Property: __name__ = 'ir.property' @@ -361,3 +369,14 @@ class CompanyReport(Report): class LetterReport(CompanyReport): __name__ = 'party.letter' + + +class Rule: + __name__ = 'ir.rule' + + @classmethod + def _get_cache_key(cls): + key = super(Rule, cls)._get_cache_key() + # XXX Use company from context instead of browse to prevent infinite + # loop, but the cache is cleared when User is written. + return key + (Transaction().context.get('company'),)