From 8c7d7e0c2f4d95dff585f0fd06b6a2376febf062 Mon Sep 17 00:00:00 2001 From: Olivier Colson Date: Tue, 25 Jun 2019 12:02:26 +0000 Subject: [PATCH] [FIX] account: correct default country on new tax repartition lines When creating a new tax, before saving, the default-computed repartition lines had no country_id associated. It only 'appeared' when saving the record. closes odoo/odoo#34359 Signed-off-by: Laurent Smet --- addons/account/models/account.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/addons/account/models/account.py b/addons/account/models/account.py index 6e7b87d3423..eb86c2da02f 100644 --- a/addons/account/models/account.py +++ b/addons/account/models/account.py @@ -1071,16 +1071,20 @@ class AccountTax(models.Model): rslt = super(AccountTax, self).default_get(vals + ['company_id']) company_id = rslt.get('company_id') + company = self.env['res.company'].browse(company_id) + if 'refund_repartition_line_ids' in vals: + # We write on the related country_id field so that the field is recomputed. Without that, it will stay empty until we save the record. rslt['refund_repartition_line_ids'] = [ - (0, 0, { 'repartition_type': 'base', 'factor_percent': 100.0, 'tag_ids': [], 'company_id': company_id}), - (0, 0, { 'repartition_type': 'tax', 'factor_percent': 100.0, 'tag_ids': [], 'company_id': company_id}), + (0, 0, { 'repartition_type': 'base', 'factor_percent': 100.0, 'tag_ids': [], 'company_id': company_id, 'country_id': company.country_id.id}), + (0, 0, { 'repartition_type': 'tax', 'factor_percent': 100.0, 'tag_ids': [], 'company_id': company_id, 'country_id': company.country_id.id}), ] if 'invoice_repartition_line_ids' in vals: + # We write on the related country_id field so that the field is recomputed. Without that, it will stay empty until we save the record. rslt['invoice_repartition_line_ids'] = [ - (0, 0, { 'repartition_type': 'base', 'factor_percent': 100.0, 'tag_ids': [], 'company_id': company_id}), - (0, 0, { 'repartition_type': 'tax', 'factor_percent': 100.0, 'tag_ids': [], 'company_id': company_id}), + (0, 0, { 'repartition_type': 'base', 'factor_percent': 100.0, 'tag_ids': [], 'company_id': company_id, 'country_id': company.country_id.id}), + (0, 0, { 'repartition_type': 'tax', 'factor_percent': 100.0, 'tag_ids': [], 'company_id': company_id, 'country_id': company.country_id.id}), ] return rslt