From 44388700ae0fc2481d0605139b17c8e2fa0ecbbf Mon Sep 17 00:00:00 2001 From: Fernando Date: Sat, 18 Apr 2026 22:02:11 -0400 Subject: [PATCH] [FIX] account_payment_term_extension: fix percentage calculation when fixed amount on first line When a payment term has a fixed amount on the first line and percentage lines after it, the percentage lines were calculated on the full invoice total instead of the remaining amount after deducting the fixed amount. This caused incorrect amounts and in some cases negative amounts on the last payment term line. Fix: use remaining_amount instead of total_amount in compute_line_amount for percentage calculations. Closes: https://github.com/OCA/account-payment/issues/924 --- .../models/account_payment_term.py | 7 ++++--- .../models/account_payment_term_line.py | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/account_payment_term_extension/models/account_payment_term.py b/account_payment_term_extension/models/account_payment_term.py index 4dd72cc1ca0..2d73fb3c774 100644 --- a/account_payment_term_extension/models/account_payment_term.py +++ b/account_payment_term_extension/models/account_payment_term.py @@ -183,12 +183,13 @@ def _compute_terms( term_vals["company_amount"] = company_line_amount term_vals["foreign_amount"] = line_amount else: - # Percentage amounts + # Percentage amounts - use remaining_amount for correct calculation + # when there are fixed amounts on previous lines line_amount = line.compute_line_amount( - total_amount, remaining_amount, precision_digits + remaining_amount, remaining_amount, precision_digits ) company_line_amount = line.compute_line_amount( - total_amount_currency, + remaining_amount_currency, remaining_amount_currency, company_precision_digits, ) diff --git a/account_payment_term_extension/models/account_payment_term_line.py b/account_payment_term_extension/models/account_payment_term_line.py index b1751250e45..590544fa5c6 100644 --- a/account_payment_term_extension/models/account_payment_term_line.py +++ b/account_payment_term_extension/models/account_payment_term_line.py @@ -150,7 +150,8 @@ def compute_line_amount(self, total_amount, remaining_amount, precision_digits): if self.value == "fixed": return float_round(self.value_amount, precision_digits=precision_digits) elif self.value in ("percent", "percent_amount_untaxed"): - amt = total_amount * self.value_amount / 100.0 + # Use remaining_amount to correctly handle fixed amounts on previous lines + amt = remaining_amount * self.value_amount / 100.0 if self.amount_round: amt = float_round(amt, precision_rounding=self.amount_round) return float_round(amt, precision_digits=precision_digits)