[FIX] account: delay l10n install

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 <qdp@odoo.com>
Signed-off-by: William André (wan) <wan@odoo.com>
This commit is contained in:
william-andre
2023-04-06 19:16:48 +02:00
parent 012d6e8981
commit 76dcc39006
2 changed files with 13 additions and 10 deletions
-6
View File
@@ -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
+13 -4
View File
@@ -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