From b373c32c4d280251d765a347cd335746bfd428ab Mon Sep 17 00:00:00 2001 From: Xavier-Do Date: Thu, 15 Jun 2023 14:20:47 +0000 Subject: [PATCH] [FIX] base: don't invalidate for all company.write The cron hr_presence will write hr_presence_last_compute_date on company leading to an invalidation of the cache. This commit makes the invalidation based on a list of field. This may break some non tested behaviour, will be a good opportunity to add test if any bugfixes is linked to this change. Part-of: odoo/odoo#119813 --- odoo/addons/base/models/res_company.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/odoo/addons/base/models/res_company.py b/odoo/addons/base/models/res_company.py index 5a279f9b5a3..a6ad022089c 100644 --- a/odoo/addons/base/models/res_company.py +++ b/odoo/addons/base/models/res_company.py @@ -223,9 +223,24 @@ class Company(models.Model): return companies + def cache_invalidation_fields(self): + # This list is not well defined and tests should be improved + return { + 'active', # user._get_company_ids and other potential cached search + 'sequence', # user._get_company_ids and other potential cached search + } + def write(self, values): - self.env.registry.clear_cache() - # Make sure that the selected currency is enabled + invalidation_fields = self.cache_invalidation_fields() + asset_invalidation_fields = {'font', 'primary_color', 'secondary_color', 'external_report_layout_id'} + if not invalidation_fields.isdisjoint(values): + self.env.registry.clear_cache() + + if not asset_invalidation_fields.isdisjoint(values): + # this is used in the content of an asset (see asset_styles_company_report) + # and thus needs to invalidate the assets cache when this is changed + self.env.registry.clear_cache('assets') # not 100% it is useful a test is missing if it is the case + if values.get('currency_id'): currency = self.env['res.currency'].browse(values['currency_id']) if not currency.active: