[FIX] account: tax included in subsequent taxes

Steps to reproduce:

1. Create a new tax (TAX1) with a lower sequence than VAT(15%).
2. Check Affect Base of subsequent taxes.
3. Create an invoice, add a line with a product and both taxes.
4. Remove the invoice line.
5. Check Journal Items tab: a VAT line is still there with an amount

Bug:

When we create an invoice line with (affecting + affected) taxes,
4 Journal items are created, including the affecting tax line
having the affected tax as tax id.
When we remove the invoice line, the system sync the dynamic lines,
recomputing all the taxes to check what to create/write/delete
As one of the tax entries has a tax it will be left as a needed line
while it should be removed.

FIX:
avoid computing `_compute_all_tax` for tax lines

closes odoo/odoo#108048

X-original-commit: 4fbd639965107fc9363dddb553a70461cd596c0c
Signed-off-by: William André (wan) <wan@odoo.com>
Signed-off-by: Walid Hanniche (waha) <waha@odoo.com>
This commit is contained in:
Walid HANNICHE (waha)
2022-12-15 13:40:59 +01:00
parent 8b2e9aa0d6
commit a7f855f789
2 changed files with 44 additions and 2 deletions
+4 -2
View File
@@ -918,14 +918,16 @@ class AccountMoveLine(models.Model):
def _compute_all_tax(self):
for line in self:
sign = line.move_id.direction_sign
if line.display_type == 'tax':
line.compute_all_tax = {}
line.compute_all_tax_dirty = False
continue
if line.display_type == 'product' and line.move_id.is_invoice(True):
amount_currency = sign * line.price_unit * (1 - line.discount / 100)
amount = sign * line.price_unit / line.currency_rate * (1 - line.discount / 100)
handle_price_include = True
quantity = line.quantity
else:
amount_currency = line.amount_currency
amount = line.balance
handle_price_include = False
quantity = 1
compute_all_currency = line.tax_ids.compute_all(
@@ -540,6 +540,46 @@ class TestAccountTaxDetailsReport(AccountTestInvoicingCommon):
)
self.assertTotalAmounts(invoice, tax_details)
def test_affect_base_amount_6(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 + affected",
'account_id': self.company_data['default_account_revenue'].id,
'quantity': 1.0,
'price_unit': 100.0,
'tax_ids': (affecting_tax + affected_tax).ids,
}),
]
})
invoice.write({'invoice_line_ids': [Command.delete(invoice.invoice_line_ids.id)]})
base_lines, tax_lines = self._dispatch_move_lines(invoice)
self.assertFalse(base_lines)
self.assertFalse(tax_lines)
tax_details = self._get_tax_details()
self.assertFalse(tax_details)
def test_round_globally_rounding(self):
self.env.company.tax_calculation_rounding_method = 'round_globally'