alberto-art3ch commented on code in PR #5825:
URL: https://github.com/apache/fineract/pull/5825#discussion_r3223566762
##########
fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/transactionprocessor/impl/AdvancedPaymentScheduleTransactionProcessor.java:
##########
@@ -650,11 +650,17 @@ private void handleInterestRefund(final LoanTransaction
loanTransaction, final T
final Money interestAfterRefund =
interestRefundService.totalInterestByTransactions(this, loan.getId(),
targetDate,
modifiedTransactions, unmodifiedTransactionIds,
ctx.getActiveLoanTermVariations());
final Money newAmount =
interestBeforeRefund.minus(progCtx.getSumOfInterestRefundAmount()).minus(interestAfterRefund);
- loanTransaction.updateAmount(newAmount.getAmount());
+
loanTransaction.updateAmount(MathUtil.negativeToZero(newAmount).getAmount());
Review Comment:
Here is a summary of what is happening in those e2e tests:
When a backdated Goodwill Credit triggers a transaction reverse-replay on a
post-maturity loan that already has Credit Balance Refunds (CBRs), the Interest
Refund transaction copy produced during replay has no
`loanTransactionRelations`, causing it to recalculate its amount against the
CBR-modified loan model. Because the CBR has already credited principal
(reducing future scheduled interest), the recalculated `interestAfterRefund`
can exceed `interestBeforeRefund`, making `newAmount` **negative or zero**. A
zero amount, when passed unconditionally to `handleRepayment`, wipes the shared
`overpaymentHolder` to zero; subsequent CBR replays then see an empty holder
and create additional installments with phantom principal outstanding equal to
the full CBR amount. The fix applies `negativeToZero` before updating the
transaction amount and adds an early-return guard that skips `handleRepayment`
entirely for zero-amount interest refunds, preserving the `overpaymentHolder`
for the CBRs t
hat follow.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]