From 5be96197388140db2ec0fc51fec154b3a14285fd Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Wed, 24 Feb 2016 16:20:21 +0100 Subject: [PATCH] [FIX] l10n_multilang: translate accounts after the installation of a CoA Before this commit, the only way to translate a chart of account was to install the language (if present in 'spoken_language' field on the chart of account configuration) **before** the installation of the chart of account. This commit loads the translations of the chart of account at the installation of the language too. To avoid recreating translations at each update of a language, skip if the language is already installed. This means than, to benefit from the fix, already deployed instances should remove (after de-activating it) the language and reinstall it to translate existing chart of account. opw-670327 Closes #11091 --- addons/l10n_multilang/l10n_multilang.py | 29 +++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/addons/l10n_multilang/l10n_multilang.py b/addons/l10n_multilang/l10n_multilang.py index 58cd5834796..921e5f7be19 100644 --- a/addons/l10n_multilang/l10n_multilang.py +++ b/addons/l10n_multilang/l10n_multilang.py @@ -84,3 +84,32 @@ class AccountChartTemplate(models.Model): 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') return self.process_translations(langs, field, in_ids, out_ids) + + +class base_language_install(models.TransientModel): + """ Install Language""" + + _inherit = "base.language.install" + + @api.multi + def lang_install(self): + self.ensure_one() + already_installed = self.env['res.lang'].search_count([('code', '=', self.lang)]) + res = super(base_language_install, self).lang_install() + if already_installed: + # update of translations instead of new installation + # skip to avoid duplicating the translations + return res + + # CoA in multilang mode + for coa in self.env['account.chart.template'].search([('spoken_languages', '!=', False)]): + if self.lang in coa.spoken_languages.split(';'): + # companies on which it is installed + for company in self.env['res.company'].search([('chart_template_id', '=', coa.id)]): + # write account.account translations in the real COA + coa._process_accounts_translations(company.id, [self.lang], 'name') + # copy account.tax translations + coa._process_taxes_translations(company.id, [self.lang], 'name') + # copy account.fiscal.position translations + coa._process_fiscal_pos_translations(company.id, [self.lang], 'name') + return res