[FIX] account_reconcile_oca: account name can be translatable

By default, account_account name is a char field. But if
l10n_multilang is installed, it is translatable, hence
the DB column is now a jsonb.
We must handle both cases in the select query.
pull/553/head
mle 2023-06-15 10:48:17 +02:00
parent 6eda7e605a
commit 4fa4e1faa1
1 changed files with 10 additions and 2 deletions

View File

@ -34,10 +34,18 @@ class AccountAccountReconcile(models.Model):
) )
def _select(self): def _select(self):
return """ account_account_name_field = self.env["ir.model.fields"].search(
[("model", "=", "account.account"), ("name", "=", "name")]
)
account_name = (
f"a.name ->> '{self.env.user.lang}'"
if account_account_name_field.translate
else "a.name"
)
return f"""
SELECT SELECT
min(aml.id) as id, min(aml.id) as id,
MAX(a.name) as name, MAX({account_name}) as name,
aml.partner_id, aml.partner_id,
a.id as account_id, a.id as account_id,
FALSE as is_reconciled, FALSE as is_reconciled,