[FIX] l10n_multilang: Getting translations of templates from records
Bug: Before the the fix, when trying to get all the translations of templates from a specific model: -All the translations for the templates of this model were catched first -> TT -All the records of this model for a specific company were catched afterwards -> RC Then, the linked between the translations(TT) and the records(RC) were made in function process_translations. But in some cases, a few records were removed and then it raised an error because the number of translations was different than the number of records. Fix: Thanks to the function create_record_with_xmlid in addons/account/models/chart_template.py, all the records created from a template have an xml_id in ir.model.data with str(company.id)+'_'+template_xmlid.name So with this way, it is possible to catch only the records created from a template. opw:767095
This commit is contained in:
@@ -73,22 +73,26 @@ class AccountChartTemplate(models.Model):
|
||||
|
||||
@api.multi
|
||||
def _process_accounts_translations(self, company_id, langs, field):
|
||||
in_ids = self.env['account.account.template'].search([('chart_template_id', '=', self.id)], order='id')
|
||||
out_ids = self.env['account.account'].search([('company_id', '=', company_id)], order='id')
|
||||
in_ids, out_ids = self._get_template_from_model(company_id, 'account.account')
|
||||
return self.process_translations(langs, field, in_ids, out_ids)
|
||||
|
||||
@api.multi
|
||||
def _process_taxes_translations(self, company_id, langs, field):
|
||||
in_ids = self.env['account.tax.template'].search([('chart_template_id', '=', self.id)], order='id')
|
||||
out_ids = self.env['account.tax'].search([('company_id', '=', company_id)], order='id')
|
||||
in_ids, out_ids = self._get_template_from_model(company_id, 'account.tax')
|
||||
return self.process_translations(langs, field, in_ids, out_ids)
|
||||
|
||||
@api.multi
|
||||
def _process_fiscal_pos_translations(self, company_id, langs, field):
|
||||
in_ids = self.env['account.fiscal.position.template'].search([('chart_template_id', '=', self.id)], order='id')
|
||||
out_ids = self.env['account.fiscal.position'].search([('company_id', '=', company_id)], order='id')
|
||||
in_ids, out_ids = self._get_template_from_model(company_id, 'account.fiscal.position')
|
||||
return self.process_translations(langs, field, in_ids, out_ids)
|
||||
|
||||
def _get_template_from_model(self, company_id, model):
|
||||
out_data = self.env['ir.model.data'].search([('model', '=', model), ('name', '=like', str(company_id)+'\_%')])
|
||||
out_ids = self.env[model].search([('id', 'in', out_data.mapped('res_id'))], order='id')
|
||||
in_xml_id_names = [xml_id.partition(str(company_id) + '_')[-1] for xml_id in out_data.mapped('name')]
|
||||
in_xml_ids = self.env['ir.model.data'].search([('model', '=', model+'.template'), ('name', 'in', in_xml_id_names)])
|
||||
in_ids = self.env[model+'.template'].search([('id', 'in', in_xml_ids.mapped('res_id'))], order='id')
|
||||
return (in_ids, out_ids)
|
||||
|
||||
class BaseLanguageInstall(models.TransientModel):
|
||||
""" Install Language"""
|
||||
|
||||
Reference in New Issue
Block a user