diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanproduct/serialization/LoanProductDataValidator.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanproduct/serialization/LoanProductDataValidator.java index 97db300d3..4d284303b 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanproduct/serialization/LoanProductDataValidator.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanproduct/serialization/LoanProductDataValidator.java @@ -2285,7 +2285,9 @@ public final class LoanProductDataValidator { considerPartialPeriodUpdates = considerPartialPeriods; } } else if (loanProduct != null) { - considerPartialPeriodUpdates = loanProduct.getLoanProductRelatedDetail().isAllowPartialPeriodInterestCalcualtion(); + if (!interestCalculationPeriodMethod.isDaily()) { + considerPartialPeriodUpdates = loanProduct.getLoanProductRelatedDetail().isAllowPartialPeriodInterestCalcualtion(); + } } if (!considerPartialPeriodUpdates) { diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanProductUpdateApiTest.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanProductUpdateApiTest.java index 07118f3f0..494e6845c 100644 --- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanProductUpdateApiTest.java +++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanProductUpdateApiTest.java @@ -91,6 +91,43 @@ public class LoanProductUpdateApiTest { } + @Test + public void loanProductWithInterestCalculationTypeDailyModifyForAdvancedPaymentAllocationRuleTest() { + // create loan product with Advanced Payment Allocation Strategy with default allocation with future installment + // allocation as NEXT_INSTALLMENT + String futureInstallmentAllocationRule = "NEXT_INSTALLMENT"; + AdvancedPaymentData defaultAllocation = createDefaultPaymentAllocation(futureInstallmentAllocationRule); + + Integer loanProductId = createLoanProductWithInterestCalculationPeriodTypeDaily(defaultAllocation); + Assertions.assertNotNull(loanProductId); + + // verify allocation rule + GetLoanProductsProductIdResponse loanProduct = LOAN_TRANSACTION_HELPER.getLoanProduct(loanProductId); + Assertions.assertNotNull(loanProduct.getPaymentAllocation()); + + Optional defaultAllocationAfterCreate = loanProduct.getPaymentAllocation().stream() + .filter(advancedPaymentData -> "DEFAULT".equals(advancedPaymentData.getTransactionType())).findFirst(); + Assertions.assertTrue(defaultAllocationAfterCreate.isPresent()); + Assertions.assertEquals(futureInstallmentAllocationRule, defaultAllocationAfterCreate.get().getFutureInstallmentAllocationRule()); + + // Change future installment allocation rule to "LAST_INSTALLMENT" and update loan product + futureInstallmentAllocationRule = "LAST_INSTALLMENT"; + defaultAllocation = createDefaultPaymentAllocation(futureInstallmentAllocationRule); + + loanProductId = updateLoanProduct(loanProductId, defaultAllocation); + Assertions.assertNotNull(loanProductId); + + loanProduct = LOAN_TRANSACTION_HELPER.getLoanProduct(loanProductId); + Assertions.assertNotNull(loanProduct.getPaymentAllocation()); + + // verify allocation rule + Optional defaultAllocationAfterUpdate = loanProduct.getPaymentAllocation().stream() + .filter(advancedPaymentData -> "DEFAULT".equals(advancedPaymentData.getTransactionType())).findFirst(); + Assertions.assertTrue(defaultAllocationAfterUpdate.isPresent()); + Assertions.assertEquals(futureInstallmentAllocationRule, defaultAllocationAfterUpdate.get().getFutureInstallmentAllocationRule()); + + } + private Integer updateLoanProduct(Integer loanProductId, AdvancedPaymentData... advancedPaymentData) { final PutLoanProductsProductIdRequest requestModifyLoan = new PutLoanProductsProductIdRequest() .transactionProcessingStrategyCode("advanced-payment-allocation-strategy") @@ -107,6 +144,16 @@ public class LoanProductUpdateApiTest { } + private Integer createLoanProductWithInterestCalculationPeriodTypeDaily(AdvancedPaymentData... advancedPaymentData) { + String loanProductCreateJSON = new LoanProductTestBuilder().withPrincipal("15,000.00").withNumberOfRepayments("4") + .withRepaymentAfterEvery("1").withRepaymentTypeAsMonth().withinterestRatePerPeriod("1") + .withInterestRateFrequencyTypeAsMonths().withAmortizationTypeAsEqualInstallments().withInterestTypeAsDecliningBalance() + .withInterestCalculationPeriodTypeAsDays().withAllowPartialPeriodInterestCalculation(false) + .addAdvancedPaymentAllocation(advancedPaymentData).build(); + return LOAN_TRANSACTION_HELPER.getLoanProductId(loanProductCreateJSON); + + } + private AdvancedPaymentData createDefaultPaymentAllocation(String futureInstallmentAllocationRule) { AdvancedPaymentData advancedPaymentData = new AdvancedPaymentData(); advancedPaymentData.setTransactionType("DEFAULT"); diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/loans/LoanProductTestBuilder.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/loans/LoanProductTestBuilder.java index 74a16498c..279e1dd7f 100644 --- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/loans/LoanProductTestBuilder.java +++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/loans/LoanProductTestBuilder.java @@ -742,4 +742,9 @@ public class LoanProductTestBuilder { return this; } + public LoanProductTestBuilder withAllowPartialPeriodInterestCalculation(final Boolean allowPartialPeriodInterestCalcualtion) { + this.allowPartialPeriodInterestCalcualtion = allowPartialPeriodInterestCalcualtion; + return this; + } + }