Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.event.business.domain.loan.LoanApprovedAmountChangedBusinessEvent;
import org.apache.fineract.infrastructure.event.business.service.BusinessEventNotifierService;
import org.apache.fineract.portfolio.common.service.Validator;
import org.apache.fineract.portfolio.loanaccount.api.LoanApiConstants;
import org.apache.fineract.portfolio.loanaccount.domain.Loan;
import org.apache.fineract.portfolio.loanaccount.domain.LoanApprovedAmountHistory;
Expand Down Expand Up @@ -58,6 +59,12 @@ public CommandProcessingResult modifyLoanApprovedAmount(final Long loanId, final

BigDecimal newApprovedAmount = command.bigDecimalValueOfParameterNamed(LoanApiConstants.amountParameterName);

if (newApprovedAmount.compareTo(loan.getApprovedPrincipal()) == 0) {
Validator.validateOrThrowDomainViolation("loan.approved.amount",
baseDataValidator -> baseDataValidator.reset().parameter(LoanApiConstants.amountParameterName).value(newApprovedAmount)
.failWithCode("must.be.different.from.current.approved.amount"));
}

LoanApprovedAmountHistory loanApprovedAmountHistory = new LoanApprovedAmountHistory(loan.getId(), newApprovedAmount,
loan.getApprovedPrincipal());

Expand Down Expand Up @@ -99,6 +106,12 @@ public CommandProcessingResult modifyLoanAvailableDisbursementAmount(Long loanId
.add(newAvailableDisbursementAmount);
changes.put("newApprovedAmount", newApprovedAmount);

if (newApprovedAmount.compareTo(loan.getApprovedPrincipal()) == 0) {
Validator.validateOrThrowDomainViolation("loan.approved.amount",
baseDataValidator -> baseDataValidator.reset().parameter(LoanApiConstants.amountParameterName).value(newApprovedAmount)
.failWithCode("must.be.different.from.current.approved.amount"));
}

LoanApprovedAmountHistory loanApprovedAmountHistory = new LoanApprovedAmountHistory(loan.getId(), newApprovedAmount,
loan.getApprovedPrincipal());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,30 @@ public void testValidLoanApprovedAmountModificationInvalidLoanStatus() {
});
}

@Test
public void testShouldFailWhenApprovedAmountIsSame() {

final PostClientsResponse client = clientHelper.createClient(ClientHelper.defaultClientCreationRequest());
final PostLoanProductsResponse loanProductsResponse = loanProductHelper.createLoanProduct(create4IProgressive());

runAt("1 January 2024", () -> {
Long loanId = applyAndApproveProgressiveLoan(client.getClientId(), loanProductsResponse.getResourceId(), "1 January 2024",
1000.0, 10.0, 4, null);

disburseLoan(loanId, BigDecimal.valueOf(100), "1 January 2024");

GetLoansLoanIdResponse loanDetails = loanTransactionHelper.getLoanDetails(loanId);
BigDecimal sameApprovedAmount = loanDetails.getApprovedPrincipal();

CallFailedRuntimeException exception = assertThrows(CallFailedRuntimeException.class,
() -> modifyLoanApprovedAmount(loanId, sameApprovedAmount));

assertEquals(403, exception.getResponse().code());
assertTrue(exception.getMessage()
.contains("validation.msg.loan.approved.amount.amount.must.be.different.from.current.approved.amount"));
});
}

@Test
public void testModifyLoanApprovedAmountTooHigh() {
BigDecimal twoThousand = BigDecimal.valueOf(2000.0);
Expand Down
Loading