SamaSVM commented on PR #6767: URL: https://github.com/apache/fineract/pull/6767#issuecomment-6523739524
@adamsaghy In `AdvancedPaymentScheduleTransactionProcessor.handleChargePayment`, the `startDate` variable was never advanced inside the installment loop. As a result, a `LoanCharge` paid through a separate `CHARGE_PAYMENT` transaction was incorrectly attributed to the last installment rather than the installment in which it was actually due. This corrupted the `LoanChargePaidBy` mapping: instead of `amount=50, installmentNumber=1`, the transaction was mapped as `amount=0, installmentNumber=12`. The fix (`startDate = installment.getDueDate();`) correctly resolves the attribution issue. However, it also exposes a side effect: once the $50 fee is correctly allocated to installment 1 instead of being lost on installment 12, the outstanding balance remaining on installment 12 after the Merchant Issued Refund changes. As a result, the loan closure behavior changes: - **Before the fix:** The loan closes immediately during Merchant Issued Refund processing. All 12 installments receive `obligations_met_on_date = 2021-01-22`. - **After the fix:** Installment 12 remains unsettled, so the loan does not close synchronously. It closes later (in the test, this is triggered by the `@AfterEach` cleanup logic; in production, it would happen when the remaining balance is eventually settled). ### Impact on Interest Accrual For progressive loans, the `ACCRUAL` transaction in this scenario is created exclusively as part of the loan-closure process (`processAccrualsOnLoanClosure`). There is no independent trigger that posts accrued interest specifically when an Interest Refund is processed. Consequently, after the fix, no `ACCRUAL` transaction is created on the refund date (`2021-01-22`). This is not caused by an incorrect accrual amount; rather, the loan-closure event that triggers accrual processing no longer occurs at that point. ### Question Requiring Clarification **Should interest accrual triggered by an Interest Refund be independent of the loan's closure status?** There are two possible approaches. The decision affects production behavior, not just the test: 1. **Keep the current behavior (post-fix state).** Accrual during an Interest Refund is created only as a side effect of loan closure. If the loan does not close immediately, as is now the case with the corrected charge allocation, no `ACCRUAL` transaction is created on the refund date. This is the behavior currently reflected in the test. 2. **Introduce an explicit accrual trigger for Interest Refunds.** Post an accrual immediately after `createInterestRefundLoanTransaction` / `LoanAccountDomainServiceJpa.makeRefund` (or within `LoanWritePlatformServiceJpaRepositoryImpl.makeRefund`), regardless of whether the loan is closed. This would make interest recognition at the time of an Interest Refund deterministic and independent of whether the outstanding balance happens to reach exactly zero. **The key decision is whether an Interest Refund should trigger interest accrual independently, or whether accrual should remain strictly tied to loan closure.** -- 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]
