Skip to content

Commit

Permalink
TA#66813 [16.0] [FIX] account_fr_ca_labels : error on installation (#222
Browse files Browse the repository at this point in the history
)

* [16.0][MIG] account_fr_ca_labels

---------

Co-authored-by: Abdellatif Benzbiria <[email protected]>
Co-authored-by: Majda EL MARIOULI <[email protected]>
  • Loading branch information
3 people authored Nov 20, 2024
1 parent f597970 commit 3e25124
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions account_fr_ca_labels/models/translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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


Expand All @@ -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(
Expand All @@ -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():
Expand All @@ -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():
Expand Down

0 comments on commit 3e25124

Please sign in to comment.