From 3e25124a0db6d09fd201bb5dee2f1a228b8e4a24 Mon Sep 17 00:00:00 2001 From: Rivo Lalaina Date: Wed, 20 Nov 2024 22:26:46 +0300 Subject: [PATCH] TA#66813 [16.0] [FIX] account_fr_ca_labels : error on installation (#222) * [16.0][MIG] account_fr_ca_labels --------- Co-authored-by: Abdellatif Benzbiria Co-authored-by: Majda EL MARIOULI --- account_fr_ca_labels/models/translate.py | 31 ++++++++++++------------ 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/account_fr_ca_labels/models/translate.py b/account_fr_ca_labels/models/translate.py index df21667..de12d7a 100644 --- a/account_fr_ca_labels/models/translate.py +++ b/account_fr_ca_labels/models/translate.py @@ -18,6 +18,8 @@ """ import threading +import psycopg2 + from odoo import api, SUPERUSER_ID, sql_db from odoo.tools.translate import TranslationImporter as BaseTranslationImporter from odoo.tools.translate import CodeTranslations as BaseCodeTranslations @@ -66,16 +68,22 @@ def get_odoo_environment(): return environment, db_cursor -def get_translation_mapping(environment, term_model): +def get_translation_mapping(environment, term_model="translate.term.fr_ca"): """ Retrieve the mapping dictionary from the specified term model. """ mapping_dict = {} if term_model in environment.registry.models: - mapping_dict = { - record.term_fr: record.term_ca - for record in environment[term_model].search([]) - } + try: + mapping_dict = { + record.term_fr: record.term_ca + for record in environment[term_model].search([]) + } + except psycopg2.errors.UndefinedTable: + # Skip if the mapping table is not yet created + # (e.g., during initial module installation) + pass + return mapping_dict @@ -88,12 +96,7 @@ def _load(self, reader, lang, xmlids=None): base_load_translation(self, reader, lang, xmlids) if lang == "fr_FR": - term_model = "translate.term.fr_ca" - mapping_dict = ( - get_translation_mapping(self.env, term_model) - if term_model in self.env.registry.models - else {} - ) + mapping_dict = get_translation_mapping(self.env) if mapping_dict: self.model_translations = replace_values( @@ -112,8 +115,7 @@ def get_web_translations(self, module_name, lang): if lang == "fr_FR": environment, db_cursor = get_odoo_environment() if environment: - term_model = "translate.term.fr_ca" - mapping_dict = get_translation_mapping(environment, term_model) + mapping_dict = get_translation_mapping(environment) for source, translated in translations.items(): for old_term, new_term in mapping_dict.items(): @@ -133,8 +135,7 @@ def get_python_translations(self, module_name, lang): if lang == "fr_FR": environment, db_cursor = get_odoo_environment() if environment: - term_model = "translate.term.fr_ca" - mapping_dict = get_translation_mapping(environment, term_model) + mapping_dict = get_translation_mapping(environment) for source, translated in translations.items(): for old_term, new_term in mapping_dict.items():