[FIX] account: Correctly translate terms when loading CoA

Bugfix: at the moment, if the environment's language is not en_US,
loading a CoA doesn't correctly load the translations: the translations
for all languages are created with the en_US terms.

Steps to reproduce:
1. Create a DB and install l10n_be.
2. Switch to French.
2. Create a new company based in Belgium.
3. Install the Belgian CoA on the company.

Expected behaviour: The accounts should be in French.
Actual behaviour: The French translation of the accounts contains
the terms in English.

Analysis:
When the records are created by _load_records(), the language of the
environment is French. As a result, all translatable terms are created
with translations in en_US and in fr_FR.
See https://github.com/odoo/odoo/blob/39292a02ab34ea86abd5601055901eb968006944/odoo/fields.py#L1762-L1771

Later on, when the translations are loaded by _load_translations,
there already exists a name->'fr_FR', so our call to
translation_importer.save(overwrite=False) doesn't want to overwrite it.
See https://github.com/odoo/odoo/blob/2780c37cfdb8560ac7c725fd27f4fe272f1d3072/addons/account/models/chart_template.py#L787

As a result, we end up with the English terms in both the en_US and
fr_FR translations.

The fix:
Set the language to en_US when calling _load_records().

closes odoo/odoo#120863

X-original-commit: 52ef69aa8423a0fd5d78af1ab018a98dba87361c
Signed-off-by: William André (wan) <wan@odoo.com>
This commit is contained in:
Antoine Dupuis (andu)
2023-05-09 11:57:39 +02:00
parent 4a71b51f59
commit 6e30206fdb
+1 -1
View File
@@ -430,7 +430,7 @@ class AccountChartTemplate(models.AbstractModel):
'values': deref(record, self.env[model]),
'noupdate': True,
})
created_vals[model] = self.env[model]._load_records(create_vals)
created_vals[model] = self.with_context(lang='en_US').env[model]._load_records(create_vals)
return created_vals
def _post_load_data(self, template_code, company, template_data):