[FIX] account: fix the use of "tax_ids" field of account.move.line

Before this fix, in 12.3, with taxes affecting subsequent taxes' base, tax_ids was used to store the taxes whose tax lines impacted current tax line's base. Before 12.3, this field was used to store the taxes whose base line has to be impacted by the current tax line.

This old behavior was changed by mistake. We restore it for consistency.

closes odoo/odoo#33471

Signed-off-by: Quentin De Paoli (qdp) <qdp@openerp.com>
This commit is contained in:
Olivier Colson
2019-05-17 12:55:11 +00:00
parent 3d97dfeb17
commit 8f7b6d0d6b
3 changed files with 21 additions and 23 deletions
+11 -5
View File
@@ -1237,6 +1237,10 @@ class AccountTax(models.Model):
all_taxes += tax
return all_taxes
def get_tax_tags(self, is_refund, repartition_type):
rep_lines = self.mapped(is_refund and 'refund_repartition_line_ids' or 'invoice_repartition_line_ids')
return rep_lines.filtered(lambda x: x.repartition_type == repartition_type).mapped('tag_ids')
@api.multi
def compute_all(self, price_unit, currency=None, quantity=1.0, product=None, partner=None, is_refund=False):
""" Returns all information required to apply taxes (in self + their children in case of a tax group).
@@ -1395,12 +1399,13 @@ class AccountTax(models.Model):
cumulated_tax_included_amount += tax_amount
# If the tax affects the base of subsequent taxes, its tax move lines must
# receive the base tags of these taxes, so that the tax report computes
# receive the base tags and tag_ids of these taxes, so that the tax report computes
# the right total
additional_tags = self.env['account.account.tag']
subsequent_taxes = self.env['account.tax']
subsequent_tags = self.env['account.account.tag']
if tax.include_base_amount:
next_taxes_rep = taxes[i+1:].mapped(is_refund and 'refund_repartition_line_ids' or 'invoice_repartition_line_ids')
additional_tags += next_taxes_rep.filtered(lambda x: x.repartition_type == 'base').mapped('tag_ids')
subsequent_taxes = taxes[i+1:]
subsequent_tags = subsequent_taxes.get_tax_tags(is_refund, 'base')
# Compute the tax lines
tax_repartition_lines = is_refund and tax.refund_repartition_line_ids or tax.invoice_repartition_line_ids
@@ -1421,7 +1426,8 @@ class AccountTax(models.Model):
'price_include': tax.price_include,
'tax_exigibility': tax.tax_exigibility,
'tax_repartition_line_id': repartition_line.id,
'tag_ids': [(6, False, (repartition_line.tag_ids + additional_tags).ids)],
'tag_ids': [(6, False, (repartition_line.tag_ids + subsequent_tags).ids)],
'tax_ids': [(6, False, subsequent_taxes.ids)]
})
total_amount += line_amount
+4 -10
View File
@@ -1078,7 +1078,7 @@ class AccountInvoice(models.Model):
else:
return self.env.ref('account.invoice_form').id
def _prepare_tax_line_vals(self, line, tax, tax_ids):
def _prepare_tax_line_vals(self, line, tax):
''' Prepare values to create an account.invoice.tax line.
:param line: An account.invoice.line record.
:param tax: Tax values outputted by compute_all() in account.tax.
@@ -1096,9 +1096,9 @@ class AccountInvoice(models.Model):
'account_analytic_id': tax['analytic'] and line.account_analytic_id.id or False,
'account_id': tax['account_id'] or line.account_id.id,
'analytic_tag_ids': tax['analytic'] and line.analytic_tag_ids.ids or False,
'tax_ids': tax_ids and [(6, None, tax_ids)] or False,
'tax_repartition_line_id': tax.get('tax_repartition_line_id'), # For base amount, we let this field empty
'tag_ids': tax['tag_ids'],
'tax_ids': tax['tax_ids'],
}
# If the taxes generate moves on the same financial account as the invoice line,
@@ -1128,7 +1128,6 @@ class AccountInvoice(models.Model):
price_unit = line.price_unit * (1 - (line.discount or 0.0) / 100.0)
taxes = line.invoice_line_tax_ids.compute_all(price_unit, self.currency_id, line.quantity, line.product_id, self.partner_id, is_refund=self.type in ('in_refund', 'out_refund'))['taxes']
affecting_base_tax_ids = []
for tax_vals in taxes:
# Retrieve the tax record (not in tax_vals when dealing with group of taxes).
if tax_map.get(tax_vals['id']):
@@ -1136,7 +1135,7 @@ class AccountInvoice(models.Model):
else:
tax = tax_map[tax_vals['id']] = self.env['account.tax'].browse(tax_vals['id'])
val = self._prepare_tax_line_vals(line, tax_vals, affecting_base_tax_ids)
val = self._prepare_tax_line_vals(line, tax_vals)
key = tax.get_grouping_key(val)
if key not in tax_grouped:
@@ -1146,11 +1145,6 @@ class AccountInvoice(models.Model):
for field in default_tax_group_fields:
tax_grouped[key][field] += round_curr(val.get(field)) or 0
if tax.amount_type == "group":
affecting_base_tax_ids += tax.children_tax_ids.filtered(lambda t: is_tax_affecting_base_amount(t)).ids
elif is_tax_affecting_base_amount(tax):
affecting_base_tax_ids.append(tax.id)
return tax_grouped
@api.multi
@@ -2146,7 +2140,7 @@ class AccountInvoiceTax(models.Model):
company_id = fields.Many2one('res.company', string='Company', related='account_id.company_id', store=True, readonly=True)
currency_id = fields.Many2one('res.currency', related='invoice_id.currency_id', store=True, readonly=True)
base = fields.Monetary(string='Base')
tax_ids = fields.Many2many('account.tax', string='Affecting Base Taxes', help='Taxes affecting the tax base amount applied before this one.')
tax_ids = fields.Many2many('account.tax', string='Affecting Base Taxes', help='Taxes whose base amount needs has to be affected by this tax line.')
tag_ids = fields.Many2many(string="Tags", comodel_name='account.account.tag', help="The taxes that will be applied on the move line generated for this tax entry")
@api.depends('amount', 'amount_rounding')
+6 -8
View File
@@ -100,8 +100,8 @@ class TestInvoiceTaxes(AccountingTestCase):
Expected:
Tax | Taxes | Base | Amount
--------------------------------------------
21% incl | / | 100 | 21
12% | 21% incl | 121 | 14.52
21% incl | 12% | 100 | 21
12% | / | 121 | 14.52
12% | / | 100 | 12
'''
invoice = self._create_invoice([
@@ -110,9 +110,8 @@ class TestInvoiceTaxes(AccountingTestCase):
])
invoice.action_invoice_open()
self.assertRecordValues(invoice.tax_line_ids.sorted(lambda x: x.amount), [
{'name': self.percent_tax_2.name, 'base': 100, 'amount': 12, 'tax_ids': []},
{'name': self.percent_tax_2.name, 'base': 121, 'amount': 14.52, 'tax_ids': [self.percent_tax_1_incl.id]},
{'name': self.percent_tax_1_incl.name, 'base': 100, 'amount': 21, 'tax_ids': []},
{'name': self.percent_tax_1_incl.name, 'base': 100, 'amount': 21, 'tax_ids': [self.percent_tax_2.id]},
{'name': self.percent_tax_2.name, 'base': 221, 'amount': 26.52, 'tax_ids': []},
])
def test_group_of_taxes(self):
@@ -135,9 +134,8 @@ class TestInvoiceTaxes(AccountingTestCase):
])
invoice.action_invoice_open()
self.assertRecordValues(invoice.tax_line_ids.sorted(lambda x: x.amount), [
{'name': self.percent_tax_2.name, 'base': 100, 'amount': 12, 'tax_ids': []},
{'name': self.percent_tax_2.name, 'base': 121, 'amount': 14.52, 'tax_ids': [self.percent_tax_1_incl.id]},
{'name': self.percent_tax_1_incl.name, 'base': 100, 'amount': 21, 'tax_ids': []},
{'name': self.percent_tax_1_incl.name, 'base': 100, 'amount': 21, 'tax_ids': [self.percent_tax_2.id]},
{'name': self.percent_tax_2.name, 'base': 221, 'amount': 26.52, 'tax_ids': []},
])
def _create_tax_tag(self, tag_name):