[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 <oco-odoo@users.noreply.github.com>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user