From c346e7af3314ce504fe3add9e9f6a4839bcad64a Mon Sep 17 00:00:00 2001 From: Nicolas Lempereur Date: Thu, 22 Aug 2019 14:29:00 +0000 Subject: [PATCH] [FIX] l10n_*: translate COA on load without install When a COA is installed being loaded for current company, the translations of taxes, account name, ... (in l10n_be, l10n_ca, l10n_ch, l10n_sa) are copied from the templates to the accounting records. This is done in `post_init_hook` which is correct since then translations are available to be copied. But when an accounting localization is already installed and we set it to a company, the translations are not copied. eg. install l10n_be for company1: accounts name are translated in french and dutch, set company2 to belgian accounting: only original language is available. With this changeset, the translation copy is also performed when an accounting localization is loaded for a company after it has been installed. note: if we install language for first times after setting accounting localizations, chart of account are translated in that language. opw-2047013 closes #35985 Signed-off-by: Nicolas Lempereur (nle) --- addons/l10n_lu/__init__.py | 7 +++++++ addons/l10n_lu/__manifest__.py | 2 +- addons/l10n_multilang/models/l10n_multilang.py | 13 +++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/addons/l10n_lu/__init__.py b/addons/l10n_lu/__init__.py index 1947891c8f5..79508eb4f80 100644 --- a/addons/l10n_lu/__init__.py +++ b/addons/l10n_lu/__init__.py @@ -1,8 +1,15 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. +from odoo import api, SUPERUSER_ID + from . import models +def _post_init_hook(cr, registry): + _preserve_tag_on_taxes(cr, registry) + env = api.Environment(cr, SUPERUSER_ID, {}) + env.ref('l10n_lu.lu_2011_chart_1').process_coa_translations() + def _preserve_tag_on_taxes(cr, registry): from odoo.addons.account.models.chart_template import preserve_existing_tags_on_taxes preserve_existing_tags_on_taxes(cr, registry, 'l10n_lu') diff --git a/addons/l10n_lu/__manifest__.py b/addons/l10n_lu/__manifest__.py index 37d0d2c73b8..99bc70bc5c9 100644 --- a/addons/l10n_lu/__manifest__.py +++ b/addons/l10n_lu/__manifest__.py @@ -43,5 +43,5 @@ Notes: 'data/account.chart.template.csv', 'data/account_chart_template_data.xml', ], - 'post_init_hook': '_preserve_tag_on_taxes', + 'post_init_hook': '_post_init_hook', } diff --git a/addons/l10n_multilang/models/l10n_multilang.py b/addons/l10n_multilang/models/l10n_multilang.py index 2f6e3731faa..51ddb70c94c 100644 --- a/addons/l10n_multilang/models/l10n_multilang.py +++ b/addons/l10n_multilang/models/l10n_multilang.py @@ -12,6 +12,19 @@ _logger = logging.getLogger(__name__) class AccountChartTemplate(models.Model): _inherit = 'account.chart.template' + def load_for_current_company(self, sale_tax_rate, purchase_tax_rate): + res = super(AccountChartTemplate, self).load_for_current_company(sale_tax_rate, purchase_tax_rate) + # Copy chart of account translations when loading chart of account + for chart_template in self.filtered('spoken_languages'): + external_id = self.env['ir.model.data'].search([ + ('model', '=', 'account.chart.template'), + ('res_id', '=', chart_template.id), + ], 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() + return res + @api.multi def process_translations(self, langs, in_field, in_ids, out_ids): """