From 3d97dfeb176acd325c0085f274ded6cc56614bad Mon Sep 17 00:00:00 2001 From: Olivier Colson Date: Thu, 23 May 2019 12:36:11 +0000 Subject: [PATCH] [FIX] account: fix default tax repartition lines creation Before that, creating a tax without any repartition line with a company_id set in create() failed to create the default ones, because they did not receive the company they had to be created for (as 'company_id' was not passed to the default_get). closes odoo/odoo#33617 Signed-off-by: oco-odoo --- addons/account/models/account.py | 12 +++++++----- addons/account/models/chart_template.py | 6 ++++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/addons/account/models/account.py b/addons/account/models/account.py index e8323f7536e..651ae7b6422 100644 --- a/addons/account/models/account.py +++ b/addons/account/models/account.py @@ -1067,18 +1067,20 @@ class AccountTax(models.Model): @api.model def default_get(self, vals): - rslt = super(AccountTax, self).default_get(vals) + # company_id is added so that we are sure to fetch a default value from it to use in repartition lines, below + rslt = super(AccountTax, self).default_get(vals + ['company_id']) + company_id = rslt.get('company_id') if 'refund_repartition_line_ids' in vals: rslt['refund_repartition_line_ids'] = [ - (0, 0, { 'repartition_type': 'base', 'factor_percent': 100.0, 'tag_ids': [], 'company_id': rslt.get('company_id')}), - (0, 0, { 'repartition_type': 'tax', 'factor_percent': 100.0, 'tag_ids': [], 'company_id': rslt.get('company_id')}), + (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}), ] if 'invoice_repartition_line_ids' in vals: rslt['invoice_repartition_line_ids'] = [ - (0, 0, { 'repartition_type': 'base', 'factor_percent': 100.0, 'tag_ids': [], 'company_id': rslt.get('company_id')}), - (0, 0, { 'repartition_type': 'tax', 'factor_percent': 100.0, 'tag_ids': [], 'company_id': rslt.get('company_id')}), + (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}), ] return rslt diff --git a/addons/account/models/chart_template.py b/addons/account/models/chart_template.py index eff7872f377..fc6fdbf175b 100644 --- a/addons/account/models/chart_template.py +++ b/addons/account/models/chart_template.py @@ -900,7 +900,9 @@ class AccountTaxTemplate(models.Model): 'account_dict': dictionary containing a to-do list with all the accounts to assign on new taxes } """ - ChartTemplate = self.env['account.chart.template'] + # default_company_id is needed in context to allow creation of default + # repartition lines on taxes + ChartTemplate = self.env['account.chart.template'].with_context(default_company_id=company.id) todo_dict = {'account.tax': {}, 'account.tax.repartition.line': {}} tax_template_to_tax = {} @@ -932,7 +934,7 @@ class AccountTaxTemplate(models.Model): # We also have to delay the assignation of accounts to repartition lines all_tax_rep_lines = tax.invoice_repartition_line_ids + tax.refund_repartition_line_ids all_template_rep_lines = template.invoice_repartition_line_ids + template.refund_repartition_line_ids - for i in range(0, len(all_tax_rep_lines)): + for i in range(0, len(all_template_rep_lines)): # We assume template and tax repartition lines are in the same order template_account = all_template_rep_lines[i].account_id if template_account: