galovics commented on code in PR #2797:
URL: https://github.com/apache/fineract/pull/2797#discussion_r1045560791
##########
fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanRepaymentScheduleProcessingWrapper.java:
##########
@@ -213,6 +213,10 @@ private Money cumulativePenaltyChargesDueWithin(final
LocalDate periodStart, fin
cumulative = cumulative.plus(loanChargeAmt);
} else if
(loanCharge.isDueForCollectionFromAndUpToAndIncluding(periodStart, periodEnd)) {
cumulative = cumulative.plus(loanCharge.amount());
+ // Special case for Loan Charges (Due Date) added the same
disbursement date
+ } else if (period.isFirstPeriod()
Review Comment:
Why don't we check directly whether the charge is due on disbursement date?
This condition is kinda confusing to me and probably to you too, that's why you
put the comment there.
Let's make it crystal clear, loan charge on disbursement date.
##########
integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanChargeSpecificDueDateTest.java:
##########
@@ -110,7 +110,60 @@ public void
testApplyLoanSpecificDueDateChargeWithDisbursementDate() {
getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec,
responseSpec, loanId);
assertNotNull(getLoansLoanIdResponse);
- validateLoanAccount(getLoansLoanIdResponse, Double.valueOf("0.00"),
Double.valueOf("0.00"));
+ validateLoanAccount(getLoansLoanIdResponse, Double.valueOf("0.00"),
Double.valueOf("0.00"), false);
+
+ }
+
+ @Test
+ public void testApplyLoanSpecificDueDatePenaltyWithDisbursementDate() {
+
+ final LocalDate todaysDate = Utils.getLocalDateOfTenant();
+
+ // Client and Loan account creation
+ final Integer clientId = ClientHelper.createClient(this.requestSpec,
this.responseSpec, "01 January 2012");
+ final GetLoanProductsProductIdResponse getLoanProductsProductResponse
= createLoanProduct(loanTransactionHelper, null);
+ assertNotNull(getLoanProductsProductResponse);
+
+ // Older date to have more than one overdue installment
+ LocalDate transactionDate = todaysDate;
+ String operationDate = Utils.dateFormatter.format(transactionDate);
+ log.info("Operation date {}", transactionDate);
+
+ // Create Loan Account
+ final Integer loanId = createLoanAccount(loanTransactionHelper,
clientId.toString(),
+ getLoanProductsProductResponse.getId().toString(),
operationDate);
+
+ // Get loan details
+ GetLoansLoanIdResponse getLoansLoanIdResponse =
loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
+ validateLoanAccount(getLoansLoanIdResponse,
Double.valueOf(principalAmount), Double.valueOf("0.00"), true);
+
+ // Apply Loan Charge with specific due date
+
+ final String feeAmount = "10.00";
+ String payloadJSON =
ChargesHelper.getLoanSpecifiedDueDateJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_FLAT,
feeAmount, true);
+ final PostChargesResponse postChargesResponse =
ChargesHelper.createLoanCharge(requestSpec, responseSpec, payloadJSON);
+ assertNotNull(postChargesResponse);
+ final Long loanChargeId = postChargesResponse.getResourceId();
Review Comment:
Let's assert that the resourceId is not null.
##########
integration-tests/src/test/java/org/apache/fineract/integrationtests/common/loans/LoanTransactionHelper.java:
##########
@@ -1563,6 +1563,14 @@ public void
validateLoanFeesOustandingBalance(GetLoansLoanIdResponse getLoansLoa
}
}
+ public void validateLoanPenaltiesOustandingBalance(GetLoansLoanIdResponse
getLoansLoanIdResponse, Double amountExpected) {
+ GetLoansLoanIdSummary getLoansLoanIdSummary =
getLoansLoanIdResponse.getSummary();
+ if (getLoansLoanIdSummary != null) {
Review Comment:
Having a null-check here and in general within tests is a really really bad
pattern cause it could prevent assertions from being evaluation therefore
making the tests pass.
##########
integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanChargeSpecificDueDateTest.java:
##########
@@ -110,7 +110,60 @@ public void
testApplyLoanSpecificDueDateChargeWithDisbursementDate() {
getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec,
responseSpec, loanId);
assertNotNull(getLoansLoanIdResponse);
- validateLoanAccount(getLoansLoanIdResponse, Double.valueOf("0.00"),
Double.valueOf("0.00"));
+ validateLoanAccount(getLoansLoanIdResponse, Double.valueOf("0.00"),
Double.valueOf("0.00"), false);
+
+ }
+
+ @Test
+ public void testApplyLoanSpecificDueDatePenaltyWithDisbursementDate() {
+
+ final LocalDate todaysDate = Utils.getLocalDateOfTenant();
+
+ // Client and Loan account creation
+ final Integer clientId = ClientHelper.createClient(this.requestSpec,
this.responseSpec, "01 January 2012");
+ final GetLoanProductsProductIdResponse getLoanProductsProductResponse
= createLoanProduct(loanTransactionHelper, null);
+ assertNotNull(getLoanProductsProductResponse);
+
+ // Older date to have more than one overdue installment
+ LocalDate transactionDate = todaysDate;
+ String operationDate = Utils.dateFormatter.format(transactionDate);
+ log.info("Operation date {}", transactionDate);
+
+ // Create Loan Account
+ final Integer loanId = createLoanAccount(loanTransactionHelper,
clientId.toString(),
+ getLoanProductsProductResponse.getId().toString(),
operationDate);
+
+ // Get loan details
+ GetLoansLoanIdResponse getLoansLoanIdResponse =
loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
+ validateLoanAccount(getLoansLoanIdResponse,
Double.valueOf(principalAmount), Double.valueOf("0.00"), true);
+
+ // Apply Loan Charge with specific due date
+
+ final String feeAmount = "10.00";
+ String payloadJSON =
ChargesHelper.getLoanSpecifiedDueDateJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_FLAT,
feeAmount, true);
+ final PostChargesResponse postChargesResponse =
ChargesHelper.createLoanCharge(requestSpec, responseSpec, payloadJSON);
+ assertNotNull(postChargesResponse);
+ final Long loanChargeId = postChargesResponse.getResourceId();
+
+ payloadJSON =
LoanTransactionHelper.getSpecifiedDueDateChargesForLoanAsJSON(loanChargeId.toString(),
operationDate, feeAmount);
+ PostLoansLoanIdChargesResponse postLoansLoanIdChargesResponse =
loanTransactionHelper.addChargeForLoan(loanId, payloadJSON,
+ responseSpec);
+ assertNotNull(postLoansLoanIdChargesResponse);
+
+ // Get loan details expecting to have a delinquency classification
+ getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec,
responseSpec, loanId);
+ validateLoanAccount(getLoansLoanIdResponse,
Double.valueOf(principalAmount), Double.valueOf("10.00"), true);
+
+ // Make a full repayment to close the Loan
+ Float amount = Float.valueOf("1010.00");
+ PostLoansLoanIdTransactionsResponse loanIdTransactionsResponse =
loanTransactionHelper.makeLoanRepayment(operationDate, amount,
+ loanId);
+ assertNotNull(loanIdTransactionsResponse);
+ log.info("Loan Transaction Id: {} {}", loanId,
loanIdTransactionsResponse.getResourceId());
+
+ getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec,
responseSpec, loanId);
+ assertNotNull(getLoansLoanIdResponse);
+ validateLoanAccount(getLoansLoanIdResponse, Double.valueOf("0.00"),
Double.valueOf("0.00"), true);
Review Comment:
Can we also validate the loan status as well? (CLOSED_OBLIGATIONS_MET)
--
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]