Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions l10n_fr_fec_oca/wizard/account_fr_fec_oca.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
+ """
Expand Down Expand Up @@ -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
+ """
Expand Down Expand Up @@ -654,7 +676,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()
Expand Down