From ec8286ce55f964c8ade00d1e39ba2ce7dfc04421 Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Wed, 29 Mar 2023 18:09:21 +0000 Subject: [PATCH] [FIX] account_edi: delay the computation of computed field MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We need to wait the registry to be totally loaded to correctly recompute the `edi_format_ids` field on all journals. opw-3200644 closes odoo/odoo#117405 X-original-commit: b68882825aa917fc2cb64b6f083811398f7fa386 Signed-off-by: William André (wan) Signed-off-by: Christophe Simonis --- .../account_edi/models/account_edi_format.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/addons/account_edi/models/account_edi_format.py b/addons/account_edi/models/account_edi_format.py index dc2fe87d7f3..c45c9a26dbb 100644 --- a/addons/account_edi/models/account_edi_format.py +++ b/addons/account_edi/models/account_edi_format.py @@ -38,8 +38,14 @@ class AccountEdiFormat(models.Model): edi_formats = super().create(vals_list) # activate by default on journal - journals = self.env['account.journal'].search([]) - journals._compute_edi_format_ids() + if not self.pool.loaded: + # The registry is not totally loaded. We cannot yet recompute the field on jourals as + # The helper methods aren't yet overwritten by all installed `l10n_` modules. + # Delay it in the register hook + self.pool._delay_compute_edi_format_ids = True + else: + journals = self.env['account.journal'].search([]) + journals._compute_edi_format_ids() # activate cron if any(edi_format._needs_web_services() for edi_format in edi_formats): @@ -47,6 +53,14 @@ class AccountEdiFormat(models.Model): return edi_formats + def _register_hook(self): + if hasattr(self.pool, "_delay_compute_edi_format_ids"): + del self.pool._delay_compute_edi_format_ids + journals = self.env['account.journal'].search([]) + journals._compute_edi_format_ids() + + return super()._register_hook() + #################################################### # Export method to override based on EDI Format ####################################################