[FIX] account: tax details: fix incorrect test
[FIX] account: tax details: correct taxes computation when using taxes affecting base with repetition 1) Let's consider then following taxes - tax 1, 42%, affecting the base - tax 2, 10% 2) Create an invoice with the following lines, and post it: - price=100, taxes=tax1 - price=100, taxes=tax2 - price=100, taxes=tax1+tax2 => The tax details should compute the following amounts: - base amount of tax 1: 200 - tax amount for tax 1: 84 - base amount of tax 2: 242 - tax amount for tax 2: 24.2 Before this fix, the base amount for tax 1 wasn't computed properly, and gave 300 instead of 200. This was because the same tax line (the one from tax1 with no tax_ids) was matching two different base lines: the one with tax1 and tax2, and the one with only tax1. closes odoo/odoo#75317 Related: odoo/enterprise#20356 Signed-off-by: Laurent Smet <smetl@users.noreply.github.com>
This commit is contained in:
@@ -185,7 +185,6 @@ class AccountMoveLine(models.Model):
|
||||
AND (
|
||||
-- keeping only the rows from affecting_base_tax_lines that end with the same taxes applied (see comment in affecting_base_tax_ids)
|
||||
NOT tax.include_base_amount
|
||||
OR tax_line_tax_ids.tax_ids IS NULL
|
||||
OR base_line_tax_ids.tax_ids[ARRAY_LENGTH(base_line_tax_ids.tax_ids, 1) - COALESCE(ARRAY_LENGTH(tax_line_tax_ids.tax_ids, 1), 0):ARRAY_LENGTH(base_line_tax_ids.tax_ids, 1)]
|
||||
= ARRAY[account_move_line.tax_line_id] || COALESCE(tax_line_tax_ids.tax_ids, ARRAY[]::INTEGER[])
|
||||
)
|
||||
|
||||
@@ -429,12 +429,6 @@ class TestAccountTaxDetailsReport(AccountTestInvoicingCommon):
|
||||
'base_amount': -10.0,
|
||||
'tax_amount': -2.0,
|
||||
},
|
||||
{
|
||||
'base_line_id': base_lines[0].id,
|
||||
'tax_line_id': tax_lines[2].id,
|
||||
'base_amount': -100.0,
|
||||
'tax_amount': -5.0,
|
||||
},
|
||||
{
|
||||
'base_line_id': base_lines[0].id,
|
||||
'tax_line_id': tax_lines[0].id,
|
||||
@@ -451,7 +445,96 @@ class TestAccountTaxDetailsReport(AccountTestInvoicingCommon):
|
||||
'base_line_id': base_lines[1].id,
|
||||
'tax_line_id': tax_lines[2].id,
|
||||
'base_amount': -100.0,
|
||||
'tax_amount': -5.0,
|
||||
'tax_amount': -10.0,
|
||||
},
|
||||
],
|
||||
)
|
||||
self.assertTotalAmounts(invoice, tax_details)
|
||||
|
||||
def test_affect_base_amount_5(self):
|
||||
affecting_tax = self.env['account.tax'].create({
|
||||
'name': 'Affecting',
|
||||
'amount': 42,
|
||||
'amount_type': 'percent',
|
||||
'type_tax_use': 'sale',
|
||||
'include_base_amount': True,
|
||||
'sequence': 0,
|
||||
})
|
||||
|
||||
affected_tax = self.env['account.tax'].create({
|
||||
'name': 'Affected',
|
||||
'amount': 10,
|
||||
'amount_type': 'percent',
|
||||
'type_tax_use': 'sale',
|
||||
'sequence': 1
|
||||
})
|
||||
|
||||
invoice = self.env['account.move'].create({
|
||||
'move_type': 'out_invoice',
|
||||
'partner_id': self.partner_a.id,
|
||||
'invoice_date': '2021-08-01',
|
||||
'invoice_line_ids': [
|
||||
Command.create({
|
||||
'name': "affecting",
|
||||
'account_id': self.company_data['default_account_revenue'].id,
|
||||
'quantity': 1.0,
|
||||
'price_unit': 100.0,
|
||||
'tax_ids': affecting_tax.ids,
|
||||
}),
|
||||
|
||||
Command.create({
|
||||
'name': "affected",
|
||||
'account_id': self.company_data['default_account_revenue'].id,
|
||||
'quantity': 1.0,
|
||||
'price_unit': 100.0,
|
||||
'tax_ids': affected_tax.ids,
|
||||
}),
|
||||
|
||||
Command.create({
|
||||
'name': "affecting + affected",
|
||||
'account_id': self.company_data['default_account_revenue'].id,
|
||||
'quantity': 1.0,
|
||||
'price_unit': 100.0,
|
||||
'tax_ids': (affecting_tax + affected_tax).ids,
|
||||
}),
|
||||
]
|
||||
})
|
||||
|
||||
base_lines, tax_lines = self._dispatch_move_lines(invoice)
|
||||
tax_details = self._get_tax_details()
|
||||
|
||||
self.assertTaxDetailsValues(
|
||||
tax_details,
|
||||
[
|
||||
{
|
||||
'base_line_id': base_lines[0].id,
|
||||
'tax_line_id': tax_lines[0].id,
|
||||
'base_amount': -100.0,
|
||||
'tax_amount': -42.0,
|
||||
},
|
||||
{
|
||||
'base_line_id': base_lines[1].id,
|
||||
'tax_line_id': tax_lines[1].id,
|
||||
'base_amount': -100.0,
|
||||
'tax_amount': -10.0,
|
||||
},
|
||||
{
|
||||
'base_line_id': base_lines[2].id,
|
||||
'tax_line_id': tax_lines[1].id,
|
||||
'base_amount': -42.0,
|
||||
'tax_amount': -4.2,
|
||||
},
|
||||
{
|
||||
'base_line_id': base_lines[2].id,
|
||||
'tax_line_id': tax_lines[1].id,
|
||||
'base_amount': -100.0,
|
||||
'tax_amount': -10.0,
|
||||
},
|
||||
{
|
||||
'base_line_id': base_lines[2].id,
|
||||
'tax_line_id': tax_lines[2].id,
|
||||
'base_amount': -100.0,
|
||||
'tax_amount': -42.0,
|
||||
},
|
||||
],
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user