From a77d80a48d8d9fd87f17bab86561e55e13fc686d Mon Sep 17 00:00:00 2001 From: Florian Gilbert Date: Fri, 27 Sep 2019 10:11:23 +0000 Subject: [PATCH] [FIX] account & l10n_ch: fix l10n_ch installation on a company And a compute field. closes odoo/odoo#37497 Signed-off-by: Cedric Snauwaert (csn) --- addons/account/models/res_config_settings.py | 2 +- addons/l10n_ch/__init__.py | 5 ++--- addons/l10n_ch/models/account_invoice.py | 4 +++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/addons/account/models/res_config_settings.py b/addons/account/models/res_config_settings.py index ada8a261cdb..ee91af9710c 100644 --- a/addons/account/models/res_config_settings.py +++ b/addons/account/models/res_config_settings.py @@ -92,7 +92,7 @@ class ResConfigSettings(models.TransientModel): if self.group_multi_currency: self.env.ref('base.group_user').write({'implied_ids': [(4, self.env.ref('product.group_sale_pricelist').id)]}) # install a chart of accounts for the given company (if required) - if self.chart_template_id and self.chart_template_id != self.company_id.chart_template_id: + if self.env.company == self.company_id and self.chart_template_id and self.chart_template_id != self.company_id.chart_template_id: self.chart_template_id._load(15.0, 15.0, self.env.company) @api.depends('company_id') diff --git a/addons/l10n_ch/__init__.py b/addons/l10n_ch/__init__.py index 66c98402d11..e80fdbe77b8 100644 --- a/addons/l10n_ch/__init__.py +++ b/addons/l10n_ch/__init__.py @@ -14,9 +14,8 @@ def init_settings(env): '''If the company is localized in Switzerland, activate the cash rounding by default. ''' # The cash rounding is activated by default only if the company is localized in Switzerland. - for company in env['res.company'].search([]): - if company.country_id != env.ref('base.ch'): - continue + ch_country = env.ref('base.ch') + for company in env['res.company'].search([('partner_id.country_id', '=', ch_country.id)]): res_config_id = env['res.config.settings'].create({ 'company_id': company.id, 'group_cash_rounding': True diff --git a/addons/l10n_ch/models/account_invoice.py b/addons/l10n_ch/models/account_invoice.py index 583f5580f12..37f5bf3ed4a 100644 --- a/addons/l10n_ch/models/account_invoice.py +++ b/addons/l10n_ch/models/account_invoice.py @@ -86,9 +86,11 @@ class AccountMove(models.Model): #We only keep the last digits of the sequence number if it is too long invoice_ref = invoice_ref[-l10n_ch_ISR_NUMBER_ISSUER_LENGTH:] internal_ref = invoice_ref.zfill(l10n_ch_ISR_NUMBER_LENGTH - l10n_ch_ISR_NUMBER_ISSUER_LENGTH - 1) # -1 for mod10r check character - record.l10n_ch_isr_number = mod10r(invoice_issuer_ref + internal_ref) record.l10n_ch_isr_number_spaced = _space_isr_number(record.l10n_ch_isr_number) + else: + record.l10n_ch_isr_number = False + record.l10n_ch_isr_number_spaced = False @api.depends( 'currency_id.name', 'amount_total', 'name',