FINERACT-2148: loan charge off behaviour configuration

This commit is contained in:
adam.magyari
2024-11-27 11:31:05 +01:00
committed by Adam Saghy
parent 240a6dffc8
commit 479e71cdad
17 changed files with 237 additions and 25 deletions
@@ -45,6 +45,7 @@ import org.apache.fineract.integrationtests.common.accounting.FinancialActivityA
import org.apache.fineract.integrationtests.common.loans.LoanProductTestBuilder;
import org.apache.fineract.integrationtests.common.loans.LoanTestLifecycleExtension;
import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper;
import org.apache.fineract.portfolio.loanaccount.domain.LoanChargeOffBehaviour;
import org.apache.fineract.portfolio.loanaccount.loanschedule.domain.LoanScheduleProcessingType;
import org.apache.fineract.portfolio.loanaccount.loanschedule.domain.LoanScheduleType;
import org.apache.fineract.portfolio.loanproduct.domain.PaymentAllocationType;
@@ -408,6 +409,50 @@ public class LoanProductWithAdvancedPaymentAllocationIntegrationTests {
loanProductError.get(0).get("defaultUserMessage").replace('`', ' '));
}
@Test
public void testCreateAndReadProgressiveLoanProductWithChargeOffBehaviour() {
// given
AdvancedPaymentData defaultAllocation = createDefaultPaymentAllocation();
AdvancedPaymentData repaymentPaymentAllocation = createRepaymentPaymentAllocation();
// when
String loanProductRequest = loanProductTestBuilder(
customization -> customization.addAdvancedPaymentAllocation(defaultAllocation, repaymentPaymentAllocation)
.withChargeOffBehaviour(LoanChargeOffBehaviour.ZERO_INTEREST));
Integer loanProductId = LOAN_TRANSACTION_HELPER.getLoanProductId(loanProductRequest);
Assertions.assertNotNull(loanProductId);
GetLoanProductsProductIdResponse loanProduct = LOAN_TRANSACTION_HELPER.getLoanProduct(loanProductId);
// then
Assertions.assertNotNull(loanProduct.getChargeOffBehaviour());
Assertions.assertEquals(LoanChargeOffBehaviour.ZERO_INTEREST.name(), loanProduct.getChargeOffBehaviour().getId());
// when a new interest refund transaction was added
LOAN_TRANSACTION_HELPER.updateLoanProduct(loanProductId.longValue(),
new PutLoanProductsProductIdRequest().chargeOffBehaviour(LoanChargeOffBehaviour.REGULAR.name()));
loanProduct = LOAN_TRANSACTION_HELPER.getLoanProduct(loanProductId);
// then
Assertions.assertNotNull(loanProduct.getChargeOffBehaviour());
Assertions.assertEquals(LoanChargeOffBehaviour.REGULAR.name(), loanProduct.getChargeOffBehaviour().getId());
}
@Test
public void testCreateCumulativeLoanProductWithChargeOff() {
// given
// when
String loanProductRequest = loanProductTestBuilder(
customization -> customization.withChargeOffBehaviour(LoanChargeOffBehaviour.ZERO_INTEREST)
.withLoanScheduleType(LoanScheduleType.CUMULATIVE).withRepaymentStrategy("mifos-standard-strategy"));
LoanTransactionHelper loanTransactionHelperBadRequest = new LoanTransactionHelper(REQUEST_SPEC,
new ResponseSpecBuilder().expectStatusCode(400).build());
List<Map<String, String>> loanProductError = loanTransactionHelperBadRequest.getLoanProductError(loanProductRequest, "errors");
Assertions.assertEquals("validation.msg.loanproduct.chargeOffBehaviour.supported.only.for.progressive.loan.charge.off.behaviour",
loanProductError.get(0).get("userMessageGlobalisationCode"));
}
private String loanProductTestBuilder(Consumer<LoanProductTestBuilder> customization) {
LoanProductTestBuilder builder = new LoanProductTestBuilder().withPrincipal("15,000.00").withNumberOfRepayments("4")
.withRepaymentAfterEvery("1").withRepaymentTypeAsMonth().withinterestRatePerPeriod("1")
@@ -31,6 +31,7 @@ import org.apache.fineract.client.models.AdvancedPaymentData;
import org.apache.fineract.client.models.CreditAllocationData;
import org.apache.fineract.integrationtests.common.Utils;
import org.apache.fineract.integrationtests.common.accounting.Account;
import org.apache.fineract.portfolio.loanaccount.domain.LoanChargeOffBehaviour;
import org.apache.fineract.portfolio.loanaccount.loanschedule.domain.LoanScheduleProcessingType;
import org.apache.fineract.portfolio.loanaccount.loanschedule.domain.LoanScheduleType;
@@ -162,6 +163,7 @@ public class LoanProductTestBuilder {
private String loanScheduleProcessingType = LoanScheduleProcessingType.HORIZONTAL.name();
private FullAccountingConfig fullAccountingConfig;
private List<String> supportedInterestRefundTypes = null;
private String chargeOffBehaviour;
public String build() {
final HashMap<String, Object> map = build(null, null);
@@ -330,6 +332,10 @@ public class LoanProductTestBuilder {
map.put("supportedInterestRefundTypes", supportedInterestRefundTypes);
}
if (this.chargeOffBehaviour != null) {
map.put("chargeOffBehaviour", chargeOffBehaviour);
}
return map;
}
@@ -801,6 +807,11 @@ public class LoanProductTestBuilder {
return this;
}
public LoanProductTestBuilder withChargeOffBehaviour(LoanChargeOffBehaviour chargeOffBehaviour) {
this.chargeOffBehaviour = chargeOffBehaviour.name();
return this;
}
public LoanProductTestBuilder withChargeOffReasonsToExpenseMappings(final Long reasonId, final Long accountId) {
if (this.chargeOffReasonsToExpenseMappings == null) {
this.chargeOffReasonsToExpenseMappings = new ArrayList<>();