diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index 6193b818ebd..3297c3718d4 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -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(): diff --git a/addons/account/tests/test_early_payment_discount.py b/addons/account/tests/test_early_payment_discount.py index e3b838646ab..96e902a1f4c 100644 --- a/addons/account/tests/test_early_payment_discount.py +++ b/addons/account/tests/test_early_payment_discount.py @@ -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):