From a8ef358e10c6c6a4c8d3eeeae0a1bcae5b090034 Mon Sep 17 00:00:00 2001 From: len Date: Tue, 2 Sep 2025 17:51:46 +0200 Subject: [PATCH 1/2] [FIX] l10n_fr_fec_oca: fix ASCII file generation for empty columns --- l10n_fr_fec_oca/wizard/account_fr_fec_oca.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/l10n_fr_fec_oca/wizard/account_fr_fec_oca.py b/l10n_fr_fec_oca/wizard/account_fr_fec_oca.py index 53e7f122b..c834aab89 100644 --- a/l10n_fr_fec_oca/wizard/account_fr_fec_oca.py +++ b/l10n_fr_fec_oca/wizard/account_fr_fec_oca.py @@ -654,7 +654,7 @@ def _csv_write_rows(self, rows): for row in rows: if encoding == "ascii": for j, _cell_content in enumerate(row): - row[j] = unidecode(row[j]) + row[j] = unidecode(row[j] or "") writer.writerow(row) fecvalue = fecfile.getvalue() From 3b91ca4090a1927f8cb66b91e94882627bebf2ad Mon Sep 17 00:00:00 2001 From: len Date: Tue, 2 Sep 2025 17:53:13 +0200 Subject: [PATCH 2/2] [IMP] l10n_fr_fec_oca: work with l10n_multilang installed --- l10n_fr_fec_oca/wizard/account_fr_fec_oca.py | 30 +++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/l10n_fr_fec_oca/wizard/account_fr_fec_oca.py b/l10n_fr_fec_oca/wizard/account_fr_fec_oca.py index c834aab89..bf9903537 100644 --- a/l10n_fr_fec_oca/wizard/account_fr_fec_oca.py +++ b/l10n_fr_fec_oca/wizard/account_fr_fec_oca.py @@ -17,6 +17,8 @@ import logging from io import StringIO +from psycopg2.extensions import AsIs + from odoo import _, api, fields, models from odoo.exceptions import AccessDenied, UserError from odoo.tools import float_is_zero @@ -328,6 +330,24 @@ def generate_fec(self): unaffected_earnings_results = self._do_query_unaffected_earnings() unaffected_earnings_line = False + # tolerate l10n_multilang translations. + # note that it becomes the default in future version, so + # we can simplify by inlining the jsonb accessor version. + name_accessor = f"%(record)s.name" + # field_accessor_en = f"%(record)s.name ->> 'en_US'" + lang_code = self.env.context.get("lang", "en_US") + name_accessor_lang = ( + f"COALESCE(%(record)s.name ->> '{lang_code}', %(record)s.name ->> 'en_US')" + ) + + aa_translated = self.env["account.account"]._fields["name"].translate + v = {"record": "aa"} + aa_name_query = name_accessor_lang % v if aa_translated else name_accessor % v + + aj_translated = self.env["account.journal"]._fields["name"].translate + v = {"record": "aj"} + aj_name_query = name_accessor_lang % v if aj_translated else name_accessor % v + # INITIAL BALANCE other than payable/receivable sql_query = """ SELECT @@ -336,7 +356,7 @@ def generate_fec(self): 'OUVERTURE/' || %(formatted_date_year)s AS EcritureNum, %(formatted_date_from)s AS EcritureDate, MIN(aa.code) AS CompteNum, - replace(replace(MIN(aa.name), '|', '/'), '\t', '') AS CompteLib, + replace(replace(MIN(%(aa_name_query)s), '|', '/'), '\t', '') AS CompteLib, '' AS CompAuxNum, '' AS CompAuxLib, '-' AS PieceRef, @@ -390,6 +410,8 @@ def generate_fec(self): "date_to": self.date_to, "company_id": company.id, "currency_digits": currency_digits, + "aa_name_query": AsIs(aa_name_query), + "aj_name_query": AsIs(aj_name_query), } self._cr.execute(sql_query, sql_args) @@ -463,7 +485,7 @@ def generate_fec(self): 'OUVERTURE/' || %(formatted_date_year)s AS EcritureNum, %(formatted_date_from)s AS EcritureDate, MIN(aa.code) AS CompteNum, - replace(MIN(aa.name), '|', '/') AS CompteLib, + replace(MIN(%(aa_name_query)s), '|', '/') AS CompteLib, """ + aux_fields_ini_bal + """ @@ -522,11 +544,11 @@ def generate_fec(self): """ SELECT REGEXP_REPLACE(replace(aj.code, '|', '/'), '[\\t\\r\\n]', ' ', 'g') AS JournalCode, - REGEXP_REPLACE(replace(aj.name, '|', '/'), '[\\t\\r\\n]', ' ', 'g') AS JournalLib, + REGEXP_REPLACE(replace(%(aj_name_query)s, '|', '/'), '[\\t\\r\\n]', ' ', 'g') AS JournalLib, REGEXP_REPLACE(replace(am.name, '|', '/'), '[\\t\\r\\n]', ' ', 'g') AS EcritureNum, TO_CHAR(am.date, 'YYYYMMDD') AS EcritureDate, aa.code AS CompteNum, - REGEXP_REPLACE(replace(aa.name, '|', '/'), '[\\t\\r\\n]', ' ', 'g') AS CompteLib, + REGEXP_REPLACE(replace(%(aa_name_query)s, '|', '/'), '[\\t\\r\\n]', ' ', 'g') AS CompteLib, """ + aux_fields + """