From 76dcc390061053c99ef23b8c93e0dec4491e381f Mon Sep 17 00:00:00 2001 From: william-andre Date: Fri, 31 Mar 2023 13:46:29 +0000 Subject: [PATCH] [FIX] account: delay l10n install MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since the `account` module contains a CoA and is installed before any other `l10n_` module, the condition `and not self.env.company.chart_template` was always preventing the installation of a foreign CoA. By delaying until the registry is fully loaded, we will take the last CoA declared in the installation stack. task-3256385 closes odoo/odoo#117944 Related: odoo/enterprise#39452 Signed-off-by: Quentin De Paoli Signed-off-by: William André (wan) --- addons/account/models/chart_template.py | 6 ------ addons/account/models/ir_module.py | 17 +++++++++++++---- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/addons/account/models/chart_template.py b/addons/account/models/chart_template.py index e56238ed080..2b95a3d3e75 100644 --- a/addons/account/models/chart_template.py +++ b/addons/account/models/chart_template.py @@ -788,9 +788,3 @@ class AccountChartTemplate(models.AbstractModel): xml_id = f"account.{company.id}_{_xml_id}" translation_importer.model_translations[mname][fname][xml_id][lang] = value translation_importer.save(overwrite=False) - - def _register_hook(self): - super()._register_hook() - if hasattr(self.env.registry, '_delayed_account_translator'): - self.env.registry._delayed_account_translator(self.env) - del self.env.registry._delayed_account_translator diff --git a/addons/account/models/ir_module.py b/addons/account/models/ir_module.py index 49d2a027485..fa1b05a1992 100644 --- a/addons/account/models/ir_module.py +++ b/addons/account/models/ir_module.py @@ -64,10 +64,7 @@ class IrModule(models.Model): super().write(vals) is_installed = len(self) == 1 and self.state == 'installed' if not was_installed and is_installed and not self.env.company.chart_template and self.account_templates: - self.env['account.chart.template'].try_loading( - next(iter(self.account_templates)), - self.env.company, - ) + self.env.registry._auto_install_template = next(iter(self.account_templates)) def _load_module_terms(self, modules, langs, overwrite=False): super()._load_module_terms(modules, langs, overwrite) @@ -78,3 +75,15 @@ class IrModule(models.Model): load_account_translations(self.env) else: self.env.registry._delayed_account_translator = load_account_translations + + def _register_hook(self): + super()._register_hook() + if hasattr(self.env.registry, '_delayed_account_translator'): + self.env.registry._delayed_account_translator(self.env) + del self.env.registry._delayed_account_translator + if hasattr(self.env.registry, '_auto_install_template'): + self.env['account.chart.template'].try_loading( + self.env.registry._auto_install_template, + self.env.company, + ) + del self.env.registry._auto_install_template