Skip to content

Commit 23afec1

Browse files
committed
[FIX] l10n_multilang: avoid module conflicts
In case two modules are using the same local name for their external identifier, a conflict may occure. e.g. the templates - l10n_generic_coa.a_salary_expense - l10n_be.a_salary_expense will generate - l10n_generic_coa.1_a_salary_expense - l10n_be.2_a_salary_expense As the previous search for in_xml_ids was using a domain ('name', '=', 'a_salary_expense') both records were returned, making in_ids to have one more record than out_ids Followup of review made at odoo#31510 closes odoo#31604 Signed-off-by: Martin Trigaux (mat) <mat@odoo.com>
1 parent 663597b commit 23afec1

File tree

1 file changed

+28
-14
lines changed

1 file changed

+28
-14
lines changed

addons/l10n_multilang/models/l10n_multilang.py

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# -*- coding: utf-8 -*-
22
# Part of Odoo. See LICENSE file for full copyright and licensing details.
33

4+
from collections import defaultdict
45
import logging
56

67
from odoo import api, models
@@ -88,20 +89,33 @@ def _process_fiscal_pos_translations(self, company_id, langs, field):
8889

8990
def _get_template_from_model(self, company_id, model):
9091
""" Find the records and their matching template """
91-
# genereated records have an external id with the format <company id>_<template id>
92-
out_data = self.env['ir.model.data'].search([('model', '=', model), ('name', '=like', str(company_id)+'\_%')])
93-
out_ids = self.env[model].browse(out_data.mapped('res_id'))
94-
95-
# templates and records may have been created in a different order
96-
# reorder them based on external id names
97-
in_xml_id_names = [xml_id.partition(str(company_id) + '_')[-1] for xml_id in out_data.mapped('name')]
98-
in_xml_id_names = {name: index for index, name in enumerate(in_xml_id_names)}
99-
100-
in_xml_ids = self.env['ir.model.data'].search([('model', '=', model+'.template'), ('name', 'in', list(in_xml_id_names))])
101-
in_xml_ids = in_xml_ids.sorted(key=lambda x: in_xml_id_names[x.name])
102-
103-
in_ids = self.env[model+'.template'].browse(in_xml_ids.mapped('res_id'))
104-
return (in_ids, out_ids)
92+
# generated records have an external id with the format <company id>_<template xml id>
93+
grouped_out_data = defaultdict(lambda: self.env['ir.model.data'])
94+
for imd in self.env['ir.model.data'].search([
95+
('model', '=', model),
96+
('name', '=like', str(company_id) + '_%')
97+
]):
98+
grouped_out_data[imd.module] += imd
99+
100+
in_records = self.env[model + '.template']
101+
out_records = self.env[model]
102+
for module, out_data in grouped_out_data.items():
103+
# templates and records may have been created in a different order
104+
# reorder them based on external id names
105+
expected_in_xml_id_names = {xml_id.name.partition(str(company_id) + '_')[-1]: xml_id for xml_id in out_data}
106+
107+
in_xml_ids = self.env['ir.model.data'].search([
108+
('model', '=', model + '.template'),
109+
('module', '=', module),
110+
('name', 'in', list(expected_in_xml_id_names))
111+
])
112+
in_xml_ids = {xml_id.name: xml_id for xml_id in in_xml_ids}
113+
114+
for name, xml_id in expected_in_xml_id_names.items():
115+
in_records += self.env[model + '.template'].browse(in_xml_ids[name].res_id)
116+
out_records += self.env[model].browse(xml_id.res_id)
117+
118+
return (in_records, out_records)
105119

106120
class BaseLanguageInstall(models.TransientModel):
107121
""" Install Language"""

0 commit comments

Comments
 (0)