[FIX] account: early payment discount: correct tax_tag_invert on tax line for included EPD

When configuring the payment term to include the EPD within the payment's journal entry on a customer invoice, the tax_tag_invert field got wrongly set as True. This was hardcoded in the code; computing the field in the regular way gives the proper value.

OPW 3754446

closes odoo/odoo#156588

Signed-off-by: Laurent Smet (las) <las@odoo.com>
This commit is contained in:
oco-odoo
2024-03-06 16:10:53 +00:00
parent 3de06d645d
commit 375d1c1c8b
2 changed files with 40 additions and 16 deletions
-1
View File
@@ -3413,7 +3413,6 @@ class AccountMove(models.Model):
'name': _("Early Payment Discount (%s)", tax.name),
'amount_currency': payment_term_line.currency_id.round(tax_detail['amount_currency'] * percentage_paid),
'balance': payment_term_line.company_currency_id.round(tax_detail['balance'] * percentage_paid),
'tax_tag_invert': True,
}
for grouping_dict, base_detail in bases_details.items():
@@ -184,6 +184,7 @@ class TestAccountEarlyPaymentDiscount(AccountTestInvoicingCommon):
'name': 'Test 0.05',
'amount_type': 'fixed',
'amount': 0.05,
'type_tax_use': 'purchase',
})
inv = self.env['account.move'].create({
@@ -194,7 +195,7 @@ class TestAccountEarlyPaymentDiscount(AccountTestInvoicingCommon):
'invoice_line_ids': [Command.create({
'name': 'line',
'price_unit': 1500.0,
'tax_ids': [Command.set(self.product_a.taxes_id.ids + fixed_tax.ids)]
'tax_ids': [Command.set(self.product_a.supplier_taxes_id.ids + fixed_tax.ids)]
})],
'invoice_payment_term_id': self.early_pay_10_percents_10_days.id,
})
@@ -206,10 +207,10 @@ class TestAccountEarlyPaymentDiscount(AccountTestInvoicingCommon):
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},
{'amount_currency': -1552.55, 'tax_tag_invert': False},
{'amount_currency': -150.0, 'tax_tag_invert': True},
{'amount_currency': -22.5, 'tax_tag_invert': True},
{'amount_currency': 1725.05, 'tax_tag_invert': False},
])
def test_register_discounted_payment_on_single_invoice_with_tax(self):
@@ -219,6 +220,30 @@ class TestAccountEarlyPaymentDiscount(AccountTestInvoicingCommon):
'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.supplier_taxes_id.ids)]})],
'invoice_payment_term_id': self.early_pay_10_percents_10_days.id,
})
inv_1500_10_percents_discount_tax_incl_15_percents_tax.action_post()
active_ids = inv_1500_10_percents_discount_tax_incl_15_percents_tax.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.5, 'tax_tag_invert': False},
{'amount_currency': -150.0, 'tax_tag_invert': True},
{'amount_currency': -22.5, 'tax_tag_invert': True},
{'amount_currency': 1725.0, 'tax_tag_invert': False},
])
def test_register_discounted_payment_on_single_out_invoice_with_tax(self):
self.early_pay_10_percents_10_days.early_pay_discount_computation = 'included'
inv_1500_10_percents_discount_tax_incl_15_percents_tax = 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': 1500.0, 'tax_ids': [Command.set(self.product_a.taxes_id.ids)]})],
'invoice_payment_term_id': self.early_pay_10_percents_10_days.id,
})
@@ -230,10 +255,10 @@ class TestAccountEarlyPaymentDiscount(AccountTestInvoicingCommon):
self.assertTrue(payments.is_reconciled)
self.assertRecordValues(payments.line_ids.sorted('balance'), [
{'amount_currency': -1552.5},
{'amount_currency': -150.0},
{'amount_currency': -22.5},
{'amount_currency': 1725.0},
{'amount_currency': -1725.0, 'tax_tag_invert': False},
{'amount_currency': 22.5, 'tax_tag_invert': False},
{'amount_currency': 150.0, 'tax_tag_invert': False},
{'amount_currency': 1552.5, 'tax_tag_invert': False},
])
def test_register_discounted_payment_multi_line_discount(self):
@@ -244,7 +269,7 @@ class TestAccountEarlyPaymentDiscount(AccountTestInvoicingCommon):
'invoice_date': '2019-01-01',
'date': '2019-01-01',
'invoice_line_ids': [
Command.create({'name': 'line', 'price_unit': 1000.0, 'tax_ids': [Command.set(self.product_a.taxes_id.ids)]}),
Command.create({'name': 'line', 'price_unit': 1000.0, 'tax_ids': [Command.set(self.product_a.supplier_taxes_id.ids)]}),
Command.create({'name': 'line', 'price_unit': 2000.0, 'tax_ids': None})
],
'invoice_payment_term_id': self.early_pay_10_percents_10_days.id,
@@ -258,11 +283,11 @@ class TestAccountEarlyPaymentDiscount(AccountTestInvoicingCommon):
self.assertTrue(payments.is_reconciled)
self.assertRecordValues(payments.line_ids.sorted('balance'), [
{'amount_currency': -2835.0},
{'amount_currency': -200.0},
{'amount_currency': -100.0},
{'amount_currency': -15.0},
{'amount_currency': 3150.0},
{'amount_currency': -2835.0, 'tax_tag_invert': False},
{'amount_currency': -200.0, 'tax_tag_invert': False},
{'amount_currency': -100.0, 'tax_tag_invert': True},
{'amount_currency': -15.0, 'tax_tag_invert': True},
{'amount_currency': 3150.0, 'tax_tag_invert': False},
])
def test_register_payment_batch_included(self):