diff --git a/addons/l10n_multilang/models/l10n_multilang.py b/addons/l10n_multilang/models/l10n_multilang.py index 2eb0124a36d..07b8e7f9633 100644 --- a/addons/l10n_multilang/models/l10n_multilang.py +++ b/addons/l10n_multilang/models/l10n_multilang.py @@ -22,7 +22,9 @@ class AccountChartTemplate(models.Model): ], order='id', limit=1) module = external_id and self.env.ref('base.module_' + external_id.module) if module and module.state == 'installed': - chart_template.process_coa_translations() + langs = chart_template._get_langs() + if langs: + chart_template._process_single_company_coa_translations(company.id, langs) return res def process_translations(self, langs, in_field, in_ids, out_ids): @@ -59,32 +61,41 @@ class AccountChartTemplate(models.Model): return True def process_coa_translations(self): - installed_langs = dict(self.env['res.lang'].get_installed()) company_obj = self.env['res.company'] for chart_template_id in self: - langs = [] - if chart_template_id.spoken_languages: - for lang in chart_template_id.spoken_languages.split(';'): - if lang not in installed_langs: - # the language is not installed, so we don't need to load its translations - continue - else: - langs.append(lang) - if langs: - company_ids = company_obj.search([('chart_template_id', '=', chart_template_id.id)]) - for company in company_ids: - # write account.account translations in the real COA - chart_template_id._process_accounts_translations(company.id, langs, 'name') - # write account.group translations - chart_template_id._process_account_group_translations(company.id, langs, 'name') - # copy account.tax name translations - chart_template_id._process_taxes_translations(company.id, langs, 'name') - # copy account.tax description translations - chart_template_id._process_taxes_translations(company.id, langs, 'description') - # copy account.fiscal.position translations - chart_template_id._process_fiscal_pos_translations(company.id, langs, 'name') + langs = chart_template_id._get_langs() + if langs: + company_ids = company_obj.search([('chart_template_id', '=', chart_template_id.id)]) + for company in company_ids: + chart_template_id._process_single_company_coa_translations(company.id, langs) return True + def _process_single_company_coa_translations(self, company_id, langs): + # write account.account translations in the real COA + self._process_accounts_translations(company_id, langs, 'name') + # write account.group translations + self._process_account_group_translations(company_id, langs, 'name') + # copy account.tax name translations + self._process_taxes_translations(company_id, langs, 'name') + # copy account.tax description translations + self._process_taxes_translations(company_id, langs, 'description') + # copy account.fiscal.position translations + self._process_fiscal_pos_translations(company_id, langs, 'name') + + def _get_langs(self): + if not self.spoken_languages: + return [] + + installed_langs = dict(self.env['res.lang'].get_installed()) + langs = [] + for lang in self.spoken_languages.split(';'): + if lang not in installed_langs: + # the language is not installed, so we don't need to load its translations + continue + else: + langs.append(lang) + return langs + def _process_accounts_translations(self, company_id, langs, field): in_ids, out_ids = self._get_template_from_model(company_id, 'account.account') return self.process_translations(langs, field, in_ids, out_ids)