[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/odoo#31510
closes odoo/odoo#31604
Signed-off-by: Martin Trigaux (mat) <mat@odoo.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from collections import defaultdict
|
||||
import logging
|
||||
|
||||
from odoo import api, models
|
||||
@@ -88,20 +89,33 @@ class AccountChartTemplate(models.Model):
|
||||
|
||||
def _get_template_from_model(self, company_id, model):
|
||||
""" Find the records and their matching template """
|
||||
# genereated records have an external id with the format <company id>_<template id>
|
||||
out_data = self.env['ir.model.data'].search([('model', '=', model), ('name', '=like', str(company_id)+'\_%')])
|
||||
out_ids = self.env[model].browse(out_data.mapped('res_id'))
|
||||
# generated records have an external id with the format <company id>_<template xml id>
|
||||
grouped_out_data = defaultdict(lambda: self.env['ir.model.data'])
|
||||
for imd in self.env['ir.model.data'].search([
|
||||
('model', '=', model),
|
||||
('name', '=like', str(company_id) + '_%')
|
||||
]):
|
||||
grouped_out_data[imd.module] += imd
|
||||
|
||||
# templates and records may have been created in a different order
|
||||
# reorder them based on external id names
|
||||
in_xml_id_names = [xml_id.partition(str(company_id) + '_')[-1] for xml_id in out_data.mapped('name')]
|
||||
in_xml_id_names = {name: index for index, name in enumerate(in_xml_id_names)}
|
||||
in_records = self.env[model + '.template']
|
||||
out_records = self.env[model]
|
||||
for module, out_data in grouped_out_data.items():
|
||||
# templates and records may have been created in a different order
|
||||
# reorder them based on external id names
|
||||
expected_in_xml_id_names = {xml_id.name.partition(str(company_id) + '_')[-1]: xml_id for xml_id in out_data}
|
||||
|
||||
in_xml_ids = self.env['ir.model.data'].search([('model', '=', model+'.template'), ('name', 'in', list(in_xml_id_names))])
|
||||
in_xml_ids = in_xml_ids.sorted(key=lambda x: in_xml_id_names[x.name])
|
||||
in_xml_ids = self.env['ir.model.data'].search([
|
||||
('model', '=', model + '.template'),
|
||||
('module', '=', module),
|
||||
('name', 'in', list(expected_in_xml_id_names))
|
||||
])
|
||||
in_xml_ids = {xml_id.name: xml_id for xml_id in in_xml_ids}
|
||||
|
||||
in_ids = self.env[model+'.template'].browse(in_xml_ids.mapped('res_id'))
|
||||
return (in_ids, out_ids)
|
||||
for name, xml_id in expected_in_xml_id_names.items():
|
||||
in_records += self.env[model + '.template'].browse(in_xml_ids[name].res_id)
|
||||
out_records += self.env[model].browse(xml_id.res_id)
|
||||
|
||||
return (in_records, out_records)
|
||||
|
||||
class BaseLanguageInstall(models.TransientModel):
|
||||
""" Install Language"""
|
||||
|
||||
Reference in New Issue
Block a user