Skip to content

Commit 3b62d56

Browse files
peter-kovacs-dpcgalovics
authored andcommitted
FINERACT-2358: Advanced-accounting-rules-based-on-write-off-reason E2E tests
1 parent c518d86 commit 3b62d56

File tree

14 files changed

+226
-9
lines changed

14 files changed

+226
-9
lines changed

fineract-accounting/src/main/java/org/apache/fineract/accounting/producttoaccountmapping/domain/ProductToGLAccountMappingRepository.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,8 @@ ProductToGLAccountMapping findBuydownFeeClassificationMapping(@Param("productId"
106106
ProductToGLAccountMapping findCapitalizedIncomeClassificationMapping(@Param("productId") Long productId,
107107
@Param("productType") Integer productType, @Param("classificationId") Long classificationId);
108108

109+
@Query("select mapping from ProductToGLAccountMapping mapping where mapping.writeOffReason.id = :writeOffReasonId AND mapping.productId = :productId AND mapping.productType = :productType")
110+
ProductToGLAccountMapping findWriteOffReasonMapping(@Param("productId") Long productId, @Param("productType") Integer productType,
111+
@Param("writeOffReasonId") Long writeOffReasonId);
112+
109113
}

fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/data/codevalue/DefaultCodeValue.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public enum DefaultCodeValue implements CodeValue {
2323
// Charge-off reason
2424
FRAUD("Fraud"), //
2525
DELINQUENT("Delinquent"), //
26-
OTHER("Other"); //
26+
OTHER("Other"), BAD_DEBT("Bad Debt"), FORGIVEN("Forgiven"), TEST("Test"); //
2727

2828
private final String customName;
2929

fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/data/loanproduct/DefaultLoanProduct.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ public enum DefaultLoanProduct implements LoanProduct {
164164
LP2_ADV_PYMNT_INTEREST_DECL_BAL_SARP_EMI_360_30_NO_INT_RECALC_MULTIDISB_PARTIAL_PERIOD, //
165165
LP2_ADV_PYMNT_INTEREST_DECL_BAL_SARP_EMI_360_30_NO_INT_RECALC_MULTIDISB_NO_PARTIAL_PERIOD, //
166166
LP2_ADV_PYMNT_INTEREST_DAILY_EMI_360_30_INTEREST_RECALCULATION_DAILY_MIN_INT_3_MAX_INT_20, //
167+
LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_WRITE_OFF_REASON_MAP, //
167168
;
168169

169170
@Override

fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/initializer/global/CodeGlobalInitializerStep.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,12 @@ public class CodeGlobalInitializerStep implements FineractGlobalInitializerStep
107107
public static final String CODE_VALUE_FAMILY_MARITAL_STATUS_WIDOWED = "Widowed";
108108
public static final Long CODE_VALUE_CONSTITUTION_ID = 24L;
109109
public static final String CODE_VALUE_CONSTITUTION_TEST = "Test";
110-
111110
public static final Long CODE_VALUE_RESCHEDULE_REASON_ID = 23L;
112111
public static final String CODE_VALUE_RESCHEDULE_REASON_TEST = "Test";
112+
public static final Long CODE_VALUE_WRITE_OFF_REASON_ID = 26L;
113+
public static final String CODE_VALUE_WRITE_OFF_REASON_TEST_1 = "Bad Debt";
114+
public static final String CODE_VALUE_WRITE_OFF_REASON_TEST_2 = "Forgiven";
115+
public static final String CODE_VALUE_WRITE_OFF_REASON_TEST_3 = "Test";
113116

114117
private final CodesApi codesApi;
115118
private final CodeValuesApi codeValuesApi;
@@ -246,6 +249,13 @@ private void createCodeValues() {
246249
List<String> rescheduleReasonNames = new ArrayList<>();
247250
rescheduleReasonNames.add(CODE_VALUE_RESCHEDULE_REASON_TEST);
248251
createCodeValues(CODE_VALUE_RESCHEDULE_REASON_ID, rescheduleReasonNames);
252+
253+
// add Write-off reasons
254+
List<String> writeOffReasonNames = new ArrayList<>();
255+
writeOffReasonNames.add(CODE_VALUE_WRITE_OFF_REASON_TEST_1);
256+
writeOffReasonNames.add(CODE_VALUE_WRITE_OFF_REASON_TEST_2);
257+
writeOffReasonNames.add(CODE_VALUE_WRITE_OFF_REASON_TEST_3);
258+
createCodeValues(CODE_VALUE_WRITE_OFF_REASON_ID, writeOffReasonNames);
249259
}
250260

251261
public void createCodeValues(Long codeId, List<String> codeValueNames) {

fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/initializer/global/LoanProductGlobalInitializerStep.java

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import org.apache.fineract.client.models.PostClassificationToIncomeAccountMappings;
4444
import org.apache.fineract.client.models.PostLoanProductsRequest;
4545
import org.apache.fineract.client.models.PostLoanProductsResponse;
46+
import org.apache.fineract.client.models.PostWriteOffReasonToExpenseAccountMappings;
4647
import org.apache.fineract.client.services.LoanProductsApi;
4748
import org.apache.fineract.test.data.AdvancePaymentsAdjustmentType;
4849
import org.apache.fineract.test.data.ChargeProductType;
@@ -55,8 +56,12 @@
5556
import org.apache.fineract.test.data.PreClosureInterestCalculationRule;
5657
import org.apache.fineract.test.data.RecalculationRestFrequencyType;
5758
import org.apache.fineract.test.data.TransactionProcessingStrategyCode;
59+
import org.apache.fineract.test.data.codevalue.CodeValue;
60+
import org.apache.fineract.test.data.codevalue.CodeValueResolver;
61+
import org.apache.fineract.test.data.codevalue.DefaultCodeValue;
5862
import org.apache.fineract.test.data.loanproduct.DefaultLoanProduct;
5963
import org.apache.fineract.test.factory.LoanProductsRequestFactory;
64+
import org.apache.fineract.test.helper.CodeHelper;
6065
import org.apache.fineract.test.helper.Utils;
6166
import org.apache.fineract.test.support.TestContext;
6267
import org.apache.fineract.test.support.TestContextKey;
@@ -69,6 +74,8 @@ public class LoanProductGlobalInitializerStep implements FineractGlobalInitializ
6974

7075
private final LoanProductsApi loanProductsApi;
7176
private final LoanProductsRequestFactory loanProductsRequestFactory;
77+
private final CodeHelper codeHelper;
78+
private final CodeValueResolver codeValueResolver;
7279

7380
@Override
7481
public void initialize() throws Exception {
@@ -1319,7 +1326,7 @@ public void initialize() throws Exception {
13191326
.recalculationRestFrequencyType(1)//
13201327
.recalculationRestFrequencyInterval(1)//
13211328
.repaymentEvery(1)//
1322-
.interestRatePerPeriod((double) 7.0)//
1329+
.interestRatePerPeriod(7D)//
13231330
.interestRateFrequencyType(INTEREST_RATE_FREQUENCY_TYPE_MONTH)//
13241331
.enableDownPayment(false)//
13251332
.interestRecalculationCompoundingMethod(0)//
@@ -3818,6 +3825,56 @@ public void initialize() throws Exception {
38183825
TestContext.INSTANCE.set(
38193826
TestContextKey.DEFAULT_LOAN_PRODUCT_CREATE_RESPONSE_LP2_PROGRESSIVE_ADV_PMNT_ALLOCATION_CAPITALIZED_INCOME_ADJ_CUSTOM_ALLOC_CLASSIFICATION_INCOME_MAP,
38203827
responseLoanProductsRequestLP2ProgressiveAdvPaymAllocCapitaizedIncomeClassificationIncomeMap);
3828+
3829+
// LP2 with progressive loan schedule + horizontal + interest EMI + 360/30
3830+
// + interest recalculation, buy down fees enabled
3831+
// + Write off reason expense map
3832+
final String name142 = DefaultLoanProduct.LP2_PROGRESSIVE_ADVANCED_PAYMENT_ALLOCATION_WRITE_OFF_REASON_MAP.getName();
3833+
final Long writeOffReasonCodeId = codeHelper.retrieveCodeByName("WriteOffReasons").getId();
3834+
final CodeValue writeOffReasonCodeValueBadDebt = DefaultCodeValue.valueOf("BAD_DEBT");
3835+
final CodeValue writeOffReasonCodeValueForgiven = DefaultCodeValue.valueOf("FORGIVEN");
3836+
final CodeValue writeOffReasonCodeValueTest = DefaultCodeValue.valueOf("TEST");
3837+
long writeOffReasonIdBadDebt = codeValueResolver.resolve(writeOffReasonCodeId, writeOffReasonCodeValueBadDebt);
3838+
long writeOffReasonIdForgiven = codeValueResolver.resolve(writeOffReasonCodeId, writeOffReasonCodeValueForgiven);
3839+
long writeOffReasonIdTest = codeValueResolver.resolve(writeOffReasonCodeId, writeOffReasonCodeValueTest);
3840+
3841+
List<PostWriteOffReasonToExpenseAccountMappings> writeOffReasonToExpenseAccountMappings = new ArrayList<>();
3842+
PostWriteOffReasonToExpenseAccountMappings writeOffReasonToExpenseAccountMappingsBadDebt = new PostWriteOffReasonToExpenseAccountMappings();
3843+
writeOffReasonToExpenseAccountMappingsBadDebt.setWriteOffReasonCodeValueId(String.valueOf(writeOffReasonIdBadDebt));
3844+
writeOffReasonToExpenseAccountMappingsBadDebt.setExpenseAccountId("12"); // Credit Loss/Bad Debt
3845+
PostWriteOffReasonToExpenseAccountMappings writeOffReasonToExpenseAccountMappingsForgiven = new PostWriteOffReasonToExpenseAccountMappings();
3846+
writeOffReasonToExpenseAccountMappingsForgiven.setWriteOffReasonCodeValueId(String.valueOf(writeOffReasonIdForgiven));
3847+
writeOffReasonToExpenseAccountMappingsForgiven.setExpenseAccountId("23"); // Buy Down Expense
3848+
PostWriteOffReasonToExpenseAccountMappings writeOffReasonToExpenseAccountMappingsTest = new PostWriteOffReasonToExpenseAccountMappings();
3849+
writeOffReasonToExpenseAccountMappingsTest.setWriteOffReasonCodeValueId(String.valueOf(writeOffReasonIdTest));
3850+
writeOffReasonToExpenseAccountMappingsTest.setExpenseAccountId("16"); // Written off
3851+
3852+
writeOffReasonToExpenseAccountMappings.add(writeOffReasonToExpenseAccountMappingsBadDebt);
3853+
writeOffReasonToExpenseAccountMappings.add(writeOffReasonToExpenseAccountMappingsForgiven);
3854+
writeOffReasonToExpenseAccountMappings.add(writeOffReasonToExpenseAccountMappingsTest);
3855+
3856+
final PostLoanProductsRequest loanProductsRequestLP2ProgressiveAdvPaymentWriteOffReasonMap = loanProductsRequestFactory
3857+
.defaultLoanProductsRequestLP2BuyDownFees()//
3858+
.name(name142)//
3859+
.transactionProcessingStrategyCode(ADVANCED_PAYMENT_ALLOCATION.getValue())//
3860+
.loanScheduleType("PROGRESSIVE") //
3861+
.isInterestRecalculationEnabled(true)//
3862+
.preClosureInterestCalculationStrategy(1)//
3863+
.rescheduleStrategyMethod(4)//
3864+
.interestRecalculationCompoundingMethod(0)//
3865+
.recalculationRestFrequencyType(2)//
3866+
.recalculationRestFrequencyInterval(1)//
3867+
.paymentAllocation(List.of(//
3868+
createPaymentAllocation("DEFAULT", "NEXT_INSTALLMENT"), //
3869+
createPaymentAllocation("GOODWILL_CREDIT", "LAST_INSTALLMENT"), //
3870+
createPaymentAllocation("MERCHANT_ISSUED_REFUND", "REAMORTIZATION"), //
3871+
createPaymentAllocation("PAYOUT_REFUND", "NEXT_INSTALLMENT")))//
3872+
.writeOffReasonsToExpenseMappings(writeOffReasonToExpenseAccountMappings);//
3873+
3874+
final Response<PostLoanProductsResponse> responseLoanProductsRequestLP2ProgressiveAdvPaymentWriteOffReasonMap = loanProductsApi
3875+
.createLoanProduct(loanProductsRequestLP2ProgressiveAdvPaymentWriteOffReasonMap).execute();
3876+
TestContext.INSTANCE.set(TestContextKey.DEFAULT_LOAN_PRODUCT_CREATE_RESPONSE_LP2_PROGRESSIVE_ADV_PYMNT_WRITE_OFF_REASON_MAP,
3877+
responseLoanProductsRequestLP2ProgressiveAdvPaymentWriteOffReasonMap);
38213878
}
38223879

38233880
public static AdvancedPaymentData createPaymentAllocation(String transactionType, String futureInstallmentAllocationRule,

fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/stepdef/loan/LoanStepDef.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3286,6 +3286,28 @@ public void writeOffLoan(String transactionDate) throws IOException {
32863286
ErrorHelper.checkSuccessfulApiCall(writeOffResponse);
32873287
}
32883288

3289+
@And("Admin does write-off the loan on {string} with write off reason: {string}")
3290+
public void writeOffLoan(String transactionDate, String writeOffReason) throws IOException {
3291+
Response<PostLoansResponse> loanResponse = testContext().get(TestContextKey.LOAN_CREATE_RESPONSE);
3292+
long loanId = loanResponse.body().getLoanId();
3293+
3294+
final Long writeOffReasonCodeId = codeHelper.retrieveCodeByName("WriteOffReasons").getId();
3295+
final CodeValue writeOffReasonCodeValueBadDebt = DefaultCodeValue.valueOf(writeOffReason);
3296+
long writeOffReasonId = codeValueResolver.resolve(writeOffReasonCodeId, writeOffReasonCodeValueBadDebt);
3297+
3298+
PostLoansLoanIdTransactionsRequest writeOffRequest = new PostLoansLoanIdTransactionsRequest()//
3299+
.transactionDate(transactionDate)//
3300+
.writeoffReasonId(writeOffReasonId)//
3301+
.dateFormat(DATE_FORMAT)//
3302+
.locale(DEFAULT_LOCALE)//
3303+
.note("Write Off");//
3304+
3305+
Response<PostLoansLoanIdTransactionsResponse> writeOffResponse = loanTransactionsApi
3306+
.executeLoanTransaction(loanId, writeOffRequest, "writeoff").execute();
3307+
testContext().set(TestContextKey.LOAN_WRITE_OFF_RESPONSE, writeOffResponse);
3308+
ErrorHelper.checkSuccessfulApiCall(writeOffResponse);
3309+
}
3310+
32893311
@Then("Admin fails to undo {string}th transaction made on {string}")
32903312
public void undoTransaction(String nthTransaction, String transactionDate) throws IOException {
32913313
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DATE_FORMAT);

fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/support/TestContextKey.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,4 +269,5 @@ public abstract class TestContextKey {
269269
public static final String DEFAULT_LOAN_PRODUCT_CREATE_RESPONSE_LP2_ADV_PYMNT_INTEREST_DECL_BAL_SARP_EMI_360_30_NO_INT_RECALC_MULTIDISB_NO_PARTIAL_PERIOD = "loanProductCreateResponseLP2AdvPmtIntDeclSarpEmi3630NoIntRecalcMutiDisbNoPartial";
270270
public static final String DEFAULT_LOAN_PRODUCT_CREATE_RESPONSE_LP2_PROGRESSIVE_ADV_PYMNT_INTEREST_RECALC_360_30_MULTIDISB_OVER_APPLIED_EXPECTED_TRANCHES = "loanProductCreateResponseLP2ProgressiveAdvancedPaymentInterestRecalculationMultidisbursalApprovedOverAppliedAmountExpectedTransches";
271271
public static final String DEFAULT_LOAN_PRODUCT_CREATE_RESPONSE_LP2_ADV_PYMNT_INTEREST_DAILY_EMI_360_30_INTEREST_RECALCULATION_DAILY_TILL_PRECLOSE_MIN_INT_3_MAX_INT_20 = "loanProductCreateResponseLP2AdvancedPaymentInterestDailyEmi36030InterestRecalculationDailyTillPreCloseMinInt3MaxInt20";
272+
public static final String DEFAULT_LOAN_PRODUCT_CREATE_RESPONSE_LP2_PROGRESSIVE_ADV_PYMNT_WRITE_OFF_REASON_MAP = "loanProductCreateResponseLP2ProgressiveAdvancedPaymentWriteOffReasonMap";
272273
}

0 commit comments

Comments
 (0)