From bb9c08d443c457d101905648fd94a8ef02a8a67c Mon Sep 17 00:00:00 2001 From: "Andrea Grazioso (agr-odoo)" Date: Thu, 12 Jan 2023 15:34:13 +0000 Subject: [PATCH] [FIX] account: extra payment lines with payment term discount In Settings>Accounting set 'Cash Discount Tax Reduction' to 'On early payment' Have a payment term 'D' with 10% discount if paid in a few days Have a fixed tax 'F' (0.04) and a percent tax 'P' (21%) Create an invoice with paymen term 'D' Have an invoice line with price unit of 100$, taxes 'P' and 'F' Post invoice and register payment (with discount) Issue: Due to the fixed tax extra lines are created in the journal entry of the payment Example: | N | Account | Taxes | Debit | Credit | |---|---------------------|-------|-------|--------| | 1 |Outstanding Receipts | | 108.94| 0.00| | 2 |Account Receivable | | 0.00| 121.04| | 3 |Cash Discount Loss | F,P| 10.0| 0.00| | 4 |Bank Suspense Account| | 0.00| 0.04| | 5 |Cash Discount Loss | | 2.10| 0.00| | 6 |Cash Discount Loss | | 0.04| 0.00| Because F is taken into account in line 3, line 6 is created, but it should not be the case opw-3119894 closes odoo/odoo#110078 X-original-commit: 4a5e696bc4507a2e6e4c03c694c4ec7e636805d7 Signed-off-by: Laurent Smet Signed-off-by: Grazioso Andrea (agr) --- addons/account/models/account_move.py | 2 ++ .../tests/test_early_payment_discount.py | 34 +++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index 8b8c99e164b..269329d4004 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -2781,6 +2781,8 @@ class AccountMove(models.Model): product_lines = self.line_ids.filtered(lambda x: x.display_type == 'product') base_lines = [x._convert_to_tax_base_line_dict() for x in product_lines] + for base_line in base_lines: + base_line['taxes'] = base_line['taxes'].filtered(lambda t: t.amount_type != 'fixed') if self.is_inbound(include_receipts=True): cash_discount_account = self.company_id.account_journal_early_pay_discount_loss_account_id diff --git a/addons/account/tests/test_early_payment_discount.py b/addons/account/tests/test_early_payment_discount.py index 27cc2a16213..3293d306440 100644 --- a/addons/account/tests/test_early_payment_discount.py +++ b/addons/account/tests/test_early_payment_discount.py @@ -124,6 +124,40 @@ class TestAccountEarlyPaymentDiscount(AccountTestInvoicingCommon): {'amount_currency': 900.0}, ]) + def test_register_discounted_payment_on_single_invoice_with_fixed_tax(self): + self.company_data['company'].early_pay_discount_computation = 'included' + fixed_tax = self.env['account.tax'].create({ + 'name': 'Test 0.05', + 'amount_type': 'fixed', + 'amount': 0.05, + }) + + inv = self.env['account.move'].create({ + 'move_type': 'in_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': 1500.0, + 'tax_ids': [Command.set(self.product_a.taxes_id.ids + fixed_tax.ids)] + })], + 'invoice_payment_term_id': self.early_pay_10_percents_10_days.id, + }) + inv.action_post() + active_ids = inv.ids + payments = self.env['account.payment.register'].with_context(active_model='account.move', active_ids=active_ids).create({ + 'payment_date': '2017-01-01', + })._create_payments() + + self.assertTrue(payments.is_reconciled) + self.assertRecordValues(payments.line_ids.sorted('balance'), [ + {'amount_currency': -1552.55}, + {'amount_currency': -150.0}, + {'amount_currency': -22.5}, + {'amount_currency': 1725.05}, + ]) + def test_register_discounted_payment_on_single_invoice_with_tax(self): self.company_data['company'].early_pay_discount_computation = 'included' inv_1500_10_percents_discount_tax_incl_15_percents_tax = self.env['account.move'].create({