details: https://code.tryton.org/tryton/commit/74f84aeb1225
branch: default
user: Cédric Krier <[email protected]>
date: Thu Jul 02 16:40:30 2026 +0200
description:
Ensure "amount to pay today" of invoice is always positive
When a payment for the invoice is booked before the maturity date, the
"amount
to pay today" must not become negative.
Closes #14924
diffstat:
modules/account_invoice/invoice.py | 2 ++
modules/account_invoice/tests/scenario_invoice.rst | 2 +-
modules/account_payment/account.py | 3 +++
3 files changed, 6 insertions(+), 1 deletions(-)
diffs (37 lines):
diff -r e4e920cb9e7d -r 74f84aeb1225 modules/account_invoice/invoice.py
--- a/modules/account_invoice/invoice.py Thu Jul 02 16:38:57 2026 +0200
+++ b/modules/account_invoice/invoice.py Thu Jul 02 16:40:30 2026 +0200
@@ -1010,6 +1010,8 @@
invoice.company.currency, amount, invoice.currency)
if invoice.type == 'in' and amount_currency:
amount_currency *= -1
+ if name == 'amount_to_pay_today':
+ amount_currency = max(0, amount_currency)
amounts[invoice.id] = amount_currency
return amounts
diff -r e4e920cb9e7d -r 74f84aeb1225
modules/account_invoice/tests/scenario_invoice.rst
--- a/modules/account_invoice/tests/scenario_invoice.rst Thu Jul 02
16:38:57 2026 +0200
+++ b/modules/account_invoice/tests/scenario_invoice.rst Thu Jul 02
16:40:30 2026 +0200
@@ -327,7 +327,7 @@
>>> pay = invoice.click('pay')
>>> pay.form.amount
- Decimal('-20.00')
+ Decimal('100.00')
>>> pay.form.amount = Decimal('99.00')
>>> pay.form.payment_method = payment_method
>>> pay.execute('choice')
diff -r e4e920cb9e7d -r 74f84aeb1225 modules/account_payment/account.py
--- a/modules/account_payment/account.py Thu Jul 02 16:38:57 2026 +0200
+++ b/modules/account_payment/account.py Thu Jul 02 16:40:30 2026 +0200
@@ -815,6 +815,9 @@
payment.currency, amount_line_paid,
invoice.currency)
amounts[invoice.id] -= payment_amount
+ if name == 'amount_to_pay_today':
+ amounts[invoice.id] = max(
+ 0, amounts[invoice.id])
return amounts
@classmethod