The issue is described in
MODINVOICE-346, but the root of the issue is in mod-finance-storage. It occurs when there are several pending payments created by an invoice approval, and at least one at the end has a negative amount.
The issue is in PendingPaymentService#updateBudgetsTotalsWithLinkedPendingPayments. In particular, applyPendingPayments calculates the new encumbrance by taking the maximum of 0 and encumbered - amount. This was probably not taking negative amounts into account.
In the example given in
MODINVOICE-346, the calculation of the new budget encumbrance is as follows:
first pending payment: max(0, 10 - 10) = 0
second: max(0, 0 - 10) = 0
third: max(0, 0-(-10)) = 10
order line encumbrance (the amount is 0 at this point because it was already released): 10 - 0 = 10
But the result should be 0...
Steps to Reproduce: