diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index 7794ae6f197..6193b818ebd 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -1968,12 +1968,10 @@ class AccountMove(models.Model): # ------------------------------------------------------------------------- def _is_eligible_for_early_payment_discount(self, currency, reference_date): self.ensure_one() - if not reference_date: - return True return self.currency_id == currency \ and self.move_type in ('out_invoice', 'out_receipt', 'in_invoice', 'in_receipt') \ and self.invoice_payment_term_id.early_discount \ - and reference_date <= self.invoice_payment_term_id._get_last_discount_date(self.invoice_date)\ + and (not reference_date or reference_date <= self.invoice_payment_term_id._get_last_discount_date(self.invoice_date)) \ and self.payment_state == 'not_paid' # ------------------------------------------------------------------------- diff --git a/addons/account/tests/test_early_payment_discount.py b/addons/account/tests/test_early_payment_discount.py index bc1dfa74c37..e3b838646ab 100644 --- a/addons/account/tests/test_early_payment_discount.py +++ b/addons/account/tests/test_early_payment_discount.py @@ -35,6 +35,22 @@ class TestAccountEarlyPaymentDiscount(AccountTestInvoicingCommon): ], }) + cls.pay_30_percents_now_balance_60_days = cls.env['account.payment.term'].create({ + 'name': '30% Now, Balance 60 Days', + 'line_ids': [ + Command.create({ + 'value_amount': 30, + 'value': 'percent', + 'nb_days': 0, + }), + Command.create({ + 'value_amount': 70, + 'value': 'percent', + 'nb_days': 60, + }) + ] + }) + def assert_tax_totals(self, document, expected_values): main_keys_to_ignore = { 'formatted_amount_total', 'formatted_amount_untaxed', 'display_tax_base', 'subtotals_order'} @@ -93,6 +109,11 @@ class TestAccountEarlyPaymentDiscount(AccountTestInvoicingCommon): report = self.env['ir.actions.report'].with_context(force_report_rendering=True)._render_qweb_pdf('account.account_invoices', res_ids=out_invoice.id) self.assertTrue(report) + #Test for invoices with multiple due dates and no early discount + out_invoice.invoice_payment_term_id = self.pay_30_percents_now_balance_60_days + new_report = self.env['ir.actions.report']._render_qweb_pdf('account.account_invoices', res_ids=out_invoice.id) + self.assertTrue(new_report) + # ========================== Tests Taxes Amounts ============================= def test_fixed_tax_amount_discounted_payment_mixed(self): fixed_tax = self.env['account.tax'].create({