Skip to content

Commit a8cb680

Browse files
Jose Alberto Hernandezadamsaghy
authored andcommitted
FINERACT-2181: Reset Last Closed Business date after Loan undo disbursement
1 parent 98b7328 commit a8cb680

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3076,6 +3076,7 @@ private Map<String, Object> undoDisbursal(final Loan loan, final ScheduleGenerat
30763076
final boolean isScheduleRegenerateRequired = loan.isActualDisbursedOnDateEarlierOrLaterThanExpected(actualDisbursementDate);
30773077
loan.setActualDisbursementDate(null);
30783078
loan.setDisbursedBy(null);
3079+
loan.setLastClosedBusinessDate(null);
30793080
final boolean isDisbursedAmountChanged = !MathUtil.isEqualTo(loan.getApprovedPrincipal(),
30803081
loan.getLoanRepaymentScheduleDetail().getPrincipal().getAmount());
30813082
loan.getLoanRepaymentScheduleDetail().setPrincipal(loan.getApprovedPrincipal());

integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanCOBCreateAccrualsTest.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
*/
1919
package org.apache.fineract.integrationtests;
2020

21+
import static org.junit.jupiter.api.Assertions.assertEquals;
22+
import static org.junit.jupiter.api.Assertions.assertNull;
23+
2124
import java.math.BigDecimal;
2225
import java.time.LocalDate;
2326
import java.util.ArrayList;
@@ -682,6 +685,46 @@ public void testProgressiveChargeBackInterestRecalculation() {
682685
});
683686
}
684687

688+
@Test
689+
public void testRunCOBJobAfterUndoDisbursement() {
690+
AtomicReference<Long> loanIdRef = new AtomicReference<>();
691+
setup();
692+
final PostLoanProductsResponse loanProductsResponse = loanProductHelper
693+
.createLoanProduct(create4IProgressive().enableAccrualActivityPosting(true));
694+
695+
runAt("1 April 2025", () -> {
696+
Long loanId = applyAndApproveProgressiveLoan(client.getClientId(), loanProductsResponse.getResourceId(), "1 March 2025", 430.0,
697+
26.0, 6, null);
698+
699+
loanIdRef.set(loanId);
700+
701+
disburseLoan(loanId, BigDecimal.valueOf(430), "1 March 2025");
702+
703+
executeInlineCOB(loanId);
704+
705+
GetLoansLoanIdResponse loanDetails = loanTransactionHelper.getLoanDetails(loanId);
706+
validateTransactionsExist(loanDetails, //
707+
transaction(9.02, "Accrual", "31 March 2025", 0.0, 0.0, 9.02, 0.0, 0.0, 0.0, 0.0));
708+
assertEquals(LocalDate.of(2025, 3, 31), loanDetails.getLastClosedBusinessDate());
709+
710+
undoDisbursement(loanId.intValue());
711+
loanDetails = loanTransactionHelper.getLoanDetails(loanId);
712+
assertNull(loanDetails.getLastClosedBusinessDate());
713+
714+
disburseLoan(loanIdRef.get(), BigDecimal.valueOf(430), "2 March 2025");
715+
loanDetails = loanTransactionHelper.getLoanDetails(loanId);
716+
assertNull(loanDetails.getLastClosedBusinessDate());
717+
});
718+
719+
runAt("2 April 2025", () -> {
720+
executeInlineCOB(loanIdRef.get());
721+
GetLoansLoanIdResponse loanDetails = loanTransactionHelper.getLoanDetails(loanIdRef.get());
722+
validateTransactionsExist(loanDetails, //
723+
transaction(9.02, "Accrual", "01 April 2025", 0.0, 0.0, 9.02, 0.0, 0.0, 0.0, 0.0));
724+
assertEquals(LocalDate.of(2025, 4, 1), loanDetails.getLastClosedBusinessDate());
725+
});
726+
}
727+
685728
private List<CreditAllocationData> chargebackCreditAllocationOrders(List<String> allocationIds) {
686729
List<CreditAllocationOrder> creditAllocationOrders = new ArrayList<>(allocationIds.size());
687730
for (int i = 0; i < allocationIds.size(); i++) {

0 commit comments

Comments
 (0)