Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions account_payment_term_extension/models/account_payment_term.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Comment on lines +186 to 195

Copilot AI Apr 19, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change modifies the core payment-term amount computation logic but there’s no test covering the fixed-first-line + subsequent percent-lines case described in issue #924. Adding a regression test for the 400 + 33% + 33% + 34% example (asserting the resulting line_ids amounts and that the last line is not negative) would prevent future reintroductions.

Copilot uses AI. Check for mistakes.
Comment on lines +186 to 195

Copilot AI Apr 19, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The percentage-amount branch now passes remaining_amount into compute_line_amount, but remaining_amount is initialized once to the invoice total and is never reduced when fixed lines are processed. As a result, percentage lines will still be computed on the full total and the reported negative-last-line scenario will persist. Consider updating remaining_amount/remaining_amount_currency inside the loop when a fixed line is applied (deduct the fixed line amount from the base used for subsequent percent lines), and keep passing total_amount/total_amount_currency as the first argument for clarity/future compatibility.

Copilot uses AI. Check for mistakes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading