FINERACT-2181: Reset Last Closed Business date after Loan undo disbursement

This commit is contained in:
Jose Alberto Hernandez
2025-07-01 20:16:15 +02:00
committed by Adam Saghy
parent 98b7328508
commit a8cb6806b0
2 changed files with 44 additions and 0 deletions
@@ -3076,6 +3076,7 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
final boolean isScheduleRegenerateRequired = loan.isActualDisbursedOnDateEarlierOrLaterThanExpected(actualDisbursementDate);
loan.setActualDisbursementDate(null);
loan.setDisbursedBy(null);
loan.setLastClosedBusinessDate(null);
final boolean isDisbursedAmountChanged = !MathUtil.isEqualTo(loan.getApprovedPrincipal(),
loan.getLoanRepaymentScheduleDetail().getPrincipal().getAmount());
loan.getLoanRepaymentScheduleDetail().setPrincipal(loan.getApprovedPrincipal());
@@ -18,6 +18,9 @@
*/
package org.apache.fineract.integrationtests;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.ArrayList;
@@ -682,6 +685,46 @@ public class LoanCOBCreateAccrualsTest extends BaseLoanIntegrationTest {
});
}
@Test
public void testRunCOBJobAfterUndoDisbursement() {
AtomicReference<Long> loanIdRef = new AtomicReference<>();
setup();
final PostLoanProductsResponse loanProductsResponse = loanProductHelper
.createLoanProduct(create4IProgressive().enableAccrualActivityPosting(true));
runAt("1 April 2025", () -> {
Long loanId = applyAndApproveProgressiveLoan(client.getClientId(), loanProductsResponse.getResourceId(), "1 March 2025", 430.0,
26.0, 6, null);
loanIdRef.set(loanId);
disburseLoan(loanId, BigDecimal.valueOf(430), "1 March 2025");
executeInlineCOB(loanId);
GetLoansLoanIdResponse loanDetails = loanTransactionHelper.getLoanDetails(loanId);
validateTransactionsExist(loanDetails, //
transaction(9.02, "Accrual", "31 March 2025", 0.0, 0.0, 9.02, 0.0, 0.0, 0.0, 0.0));
assertEquals(LocalDate.of(2025, 3, 31), loanDetails.getLastClosedBusinessDate());
undoDisbursement(loanId.intValue());
loanDetails = loanTransactionHelper.getLoanDetails(loanId);
assertNull(loanDetails.getLastClosedBusinessDate());
disburseLoan(loanIdRef.get(), BigDecimal.valueOf(430), "2 March 2025");
loanDetails = loanTransactionHelper.getLoanDetails(loanId);
assertNull(loanDetails.getLastClosedBusinessDate());
});
runAt("2 April 2025", () -> {
executeInlineCOB(loanIdRef.get());
GetLoansLoanIdResponse loanDetails = loanTransactionHelper.getLoanDetails(loanIdRef.get());
validateTransactionsExist(loanDetails, //
transaction(9.02, "Accrual", "01 April 2025", 0.0, 0.0, 9.02, 0.0, 0.0, 0.0, 0.0));
assertEquals(LocalDate.of(2025, 4, 1), loanDetails.getLastClosedBusinessDate());
});
}
private List<CreditAllocationData> chargebackCreditAllocationOrders(List<String> allocationIds) {
List<CreditAllocationOrder> creditAllocationOrders = new ArrayList<>(allocationIds.size());
for (int i = 0; i < allocationIds.size(); i++) {