From fc213e5c66ea4abef3450a14e33edae9fc66c012 Mon Sep 17 00:00:00 2001 From: "Andrea Grazioso (agr-odoo)" Date: Wed, 31 May 2023 10:18:57 +0000 Subject: [PATCH] [FIX] account: clear epd discount tax MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Set "Cash Discount Tax Reduction" to "Always" Have Tax A and Tax B Create an invoice with a payment term having a discount (example: 2/7 Net 30) Add the following lines 1) Any prod, Tax A 2) Any prod, Tax B In journal items tab we will see 2 line for the product, 2 for tax, 3 for epd, 2 for epd tax discount, 1 for payment Delete line 2) Check journal items Issue: epd discount for tax B is still there This occurs because: - When calculating the epd vals we don't actually issue a clear command - Due to a `_sync_dynamic_line` optimization we may write on a line scheduled for delete instead of creating a new one As result an old tax may be left in the overwritten line opw-3285534 closes odoo/odoo#123697 X-original-commit: bc83baf7d6be3a9ab25da90ddf1882c1cb95217e Signed-off-by: Grazioso Andrea (agr) Signed-off-by: William André (wan) --- addons/account/models/account_move_line.py | 2 +- .../tests/test_early_payment_discount.py | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/addons/account/models/account_move_line.py b/addons/account/models/account_move_line.py index 5507e80dc68..337453ccfc9 100644 --- a/addons/account/models/account_move_line.py +++ b/addons/account/models/account_move_line.py @@ -1005,7 +1005,7 @@ class AccountMoveLine(models.Model): 'amount_currency': 0.0, 'balance': 0.0, 'price_subtotal': 0.0, - 'tax_ids': [], + 'tax_ids': [Command.clear()], }, ) epd_needed_vals['amount_currency'] += line.amount_currency * percentage diff --git a/addons/account/tests/test_early_payment_discount.py b/addons/account/tests/test_early_payment_discount.py index 5401d5eea09..5f3a5fdad3e 100644 --- a/addons/account/tests/test_early_payment_discount.py +++ b/addons/account/tests/test_early_payment_discount.py @@ -581,3 +581,30 @@ class TestAccountEarlyPaymentDiscount(AccountTestInvoicingCommon): self.assertEqual(len(inv.line_ids), 3) # 1 prod, 1 tax, 1 payment terms inv.write({'invoice_payment_term_id': self.early_pay_10_percents_10_days.id}) self.assertEqual(len(inv.line_ids), 6) + + def test_mixed_epd_with_tax_deleted_line(self): + self.early_pay_10_percents_10_days.write({'early_pay_discount_computation': 'mixed'}) + tax_a = self.env['account.tax'].create({ + 'name': 'Test A', + 'amount': 10, + }) + tax_b = self.env['account.tax'].create({ + 'name': 'Test B', + 'amount': 15, + }) + + inv = self.env['account.move'].create({ + 'move_type': 'out_invoice', + 'partner_id': self.partner_a.id, + 'invoice_date': '2019-01-01', + 'date': '2019-01-01', + 'invoice_line_ids': [ + Command.create({'name': 'line', 'price_unit': 100.0, 'tax_ids': [Command.set(tax_a.ids)]}), + Command.create({'name': 'line2', 'price_unit': 100.0, 'tax_ids': [Command.set(tax_b.ids)]}), + ], + 'invoice_payment_term_id': self.early_pay_10_percents_10_days.id, + }) + self.assertEqual(len(inv.line_ids), 10) # 2 prod, 2 tax, 3 epd, 2 epd tax discount, 1 payment terms + inv.invoice_line_ids[1].unlink() + self.assertEqual(len(inv.line_ids), 6) # 1 prod, 1 tax, 2 epd, 1 epd tax discount, 1 payment terms + self.assertEqual(inv.amount_tax, 9.00) # $100.0 @ 10% tax (-10% epd)