[FIX] account: on chart reload: fix matching journals without xmlid
Currently there is the following problem when reloading the chart.
Journals without xmlid may not be matched to chart data correctly
(via code or name).
This then leads to duplicate journals being created / uniqueness
constraint issues on journal codes.
The matching happens in `_pre_reload_data`.
This should only be a problem for upgrade or user created journals
since journals created from the chart data have an xmlid.
The problem was introduced in commit d6695f2892ded178371f6c69cf594037c19ce438 :
(1) We load the chart data in en_US to be able to use the code translations
(2) We switched the language of the loading process to en_US
(to switch the chart data to en_US for the previous point and to
avoid inconsistencies)
When matching journals in the DB by code or name to the chart data:
- We fetch the en_US name of the journals in the DB due to (2);
Code is not translatable.
- We compare those values (journal code / name) against the en_US term
due to (1).
Thus the matching fails.
This commit improves the matching:
We also compare the name and code (still en_US version)
against the translated values.
closes odoo/odoo#159871
X-original-commit: 005ebd59cba6b6ca20c736c46d89259af8bd251a
Signed-off-by: William André (wan) <wan@odoo.com>
Signed-off-by: Sven Führ (svfu) <svfu@odoo.com>
This commit is contained in:
@@ -244,17 +244,20 @@ class AccountChartTemplate(models.AbstractModel):
|
||||
del data['account.journal'][xmlid]
|
||||
else:
|
||||
journal = None
|
||||
lang = self._get_untranslatable_fields_target_language(company.chart_template, company)
|
||||
translated_code = self._get_field_translation(journal_data, 'code', lang)
|
||||
if 'code' in journal_data:
|
||||
journal = self.env['account.journal'].with_context(active_test=False).search([
|
||||
*self.env['account.journal']._check_company_domain(company),
|
||||
('code', '=', journal_data['code']),
|
||||
('code', 'in', (journal_data['code'], translated_code)),
|
||||
])
|
||||
# Try to match by journal name to avoid conflict in the unique constraint on the mail alias
|
||||
translated_name = self._get_field_translation(journal_data, 'name', lang)
|
||||
if not journal and 'name' in journal_data and 'type' in journal_data:
|
||||
journal = self.env['account.journal'].with_context(active_test=False).search([
|
||||
*self.env['account.journal']._check_company_domain(company),
|
||||
('type', '=', journal_data['type']),
|
||||
('name', '=', journal_data['name']),
|
||||
('name', 'in', (journal_data['name'], translated_name)),
|
||||
], limit=1)
|
||||
if journal:
|
||||
del data['account.journal'][xmlid]
|
||||
|
||||
Reference in New Issue
Block a user