From 8317ec29ed91bf0e8c01fe8593efda9ce91d4844 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Soma=20S=C3=B6r=C3=B6s?= Date: Thu, 17 Sep 2026 12:52:29 +0200 Subject: [PATCH 1/2] FINERACT-2455: WC - Backdated discount fee adjustment on a re-charged-off loan should correct realized income e2e tests --- .../WorkingCapitalLoanAccountStepDef.java | 2 + .../WorkingCapitalLoanChargeOff.feature | 61 +++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/stepdef/loan/WorkingCapitalLoanAccountStepDef.java b/fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/stepdef/loan/WorkingCapitalLoanAccountStepDef.java index ffe8e9400cc..9dc3db2b765 100644 --- a/fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/stepdef/loan/WorkingCapitalLoanAccountStepDef.java +++ b/fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/stepdef/loan/WorkingCapitalLoanAccountStepDef.java @@ -4110,6 +4110,8 @@ private void assertBalanceFieldEquals(final String field, final String expected) final GetBalance balance = retrieveLoanDetails(getCreatedLoanId()).getBalance(); assertNotNull(balance, "Balance payload should not be null"); final BigDecimal actual = switch (field) { + case "totalDiscountFee" -> balance.getTotalDiscountFee(); + case "totalDiscountFeeAdjustment" -> balance.getTotalDiscountFeeAdjustment(); case "overpaymentAmount" -> balance.getOverpaymentAmount(); case "principalOutstanding" -> balance.getPrincipalOutstanding(); case "totalPaidPrincipal" -> balance.getPrincipalPaid(); diff --git a/fineract-e2e-tests-runner/src/test/resources/features/WorkingCapitalLoanChargeOff.feature b/fineract-e2e-tests-runner/src/test/resources/features/WorkingCapitalLoanChargeOff.feature index 43a85514ee8..33fff685250 100644 --- a/fineract-e2e-tests-runner/src/test/resources/features/WorkingCapitalLoanChargeOff.feature +++ b/fineract-e2e-tests-runner/src/test/resources/features/WorkingCapitalLoanChargeOff.feature @@ -449,3 +449,64 @@ Feature: Working Capital Loan Charge-off | 10 January 2026 | Repayment | 60.0 | 60.0 | 0.0 | 0.0 | false | | 15 January 2026 | Charge-off | 60.0 | 60.0 | 0.0 | 0.0 | true | Then Working Capital loan status will be "CLOSED_OBLIGATIONS_MET" + + @TestRailId:TODO_ADD_01 + Scenario: Verify Working Capital Charge-off transactions - Backdated discount fee adjustment on a re-charged-off loan should correct realized income +# Step 1: WC loan 9000 / total payment volume 100000 / rate 18, approve and disburse on 01 January 2026 with discount 1000. + When Admin sets the business date to "01 January 2026" + And Admin creates a client with random data + And Admin creates a working capital loan with the following data: + | LoanProduct | submittedOnDate | expectedDisbursementDate | principalAmount | totalPaymentVolume | periodPaymentRate | discount | + | WCLP_ADVANCED_ACCOUNTING | 01 January 2026 | 01 January 2026 | 9000 | 100000 | 18 | 1000 | + And Admin successfully approves the working capital loan on "01 January 2026" with "9000" amount and expected disbursement date on "01 January 2026" + And Admin successfully disburse the Working Capital loan on "01 January 2026" with "9000" EUR transaction amount and "1000" discount amount + And Admin loads discount fee transaction from Working Capital loan for adjustment + +# Step 2: 02 January 2026 -> repayment 50; run COB (amortization 9.61). + And Admin sets the business date to "02 January 2026" + And Admin runs inline COB job for Working Capital Loan by loanId + When Customer makes "REPAYMENT" transaction on "02 January 2026" with 50.0 transaction amount on Working Capital loan + +# Step 3: 04 January 2026 -> charge off (9950, final amortization 990.39 to charge-off expense). + And Admin sets the business date to "04 January 2026" + And Admin runs inline COB job for Working Capital Loan by loanId + When Admin charges off the Working Capital loan on "04 January 2026" + +# Step 4: 05 January 2026 -> repayment 9950 dated 03 January 2026 (charge-off is lifted, loan CLOSED, amortization 990.39 posted to income, realized 1000.00). + And Admin sets the business date to "05 January 2026" + And Admin runs inline COB job for Working Capital Loan by loanId + When Customer makes "REPAYMENT" transaction on "03 January 2026" with 9950.0 transaction amount on Working Capital loan + +# Step 5: Undo that repayment (loan ACTIVE, outstanding 9950, not charged off, realized still 1000.00). + When Customer undo "1"th working capital transaction made on "03 January 2026" + +# Step 6: Charge off again on 05 January 2026 (no final amortization, deferred income already 0). + When Admin charges off the Working Capital loan on "05 January 2026" + +# Step 7: Discount fee adjustment 100 dated 03 January 2026 (before the charge-off date, accepted). + And Admin adds Discount fee adjustment with "100" amount on transaction date "03 January 2026" on Working Capital loan account for last discount + +# Step 8: Run COB on the following days. + And Admin sets the business date to "06 January 2026" + And Admin runs inline COB job for Working Capital Loan by loanId + + And Working Capital loan balance payload contains the following fields: + | field | value | + | totalDiscountFee | 1000.0 | + | totalDiscountFeeAdjustment | 100.0 | + | realizedIncome | 900.0 | + | unrealizedIncome | 0.0 | + +# Step 9: Undo the Discount Fee adjustment + When Admin undo the Discount fee adjustment with "100.0" amount on Working Capital loan account + +# Step 10: Run COB on the following days. + And Admin sets the business date to "07 January 2026" + And Admin runs inline COB job for Working Capital Loan by loanId + + And Working Capital loan balance payload contains the following fields: + | field | value | + | totalDiscountFee | 1000.0 | + | totalDiscountFeeAdjustment | 000.0 | + | realizedIncome | 1000.0 | + | unrealizedIncome | 0.0 | From 51c420bf33052b73c54454e105e5114dad00e566 Mon Sep 17 00:00:00 2001 From: Rustam Zeinalov Date: Mon, 21 Sep 2026 14:36:35 +0200 Subject: [PATCH 2/2] FINERACT-2455: updated e2e scenario for validation of WC - Backdated discount fee adjustment on a re-charged-off loan should correct realized income e2e tests --- .../WorkingCapitalLoanChargeOff.feature | 10 +-- ...kingCapitalLoanChargeOffAccounting.feature | 71 +++++++++++++++++++ 2 files changed, 76 insertions(+), 5 deletions(-) diff --git a/fineract-e2e-tests-runner/src/test/resources/features/WorkingCapitalLoanChargeOff.feature b/fineract-e2e-tests-runner/src/test/resources/features/WorkingCapitalLoanChargeOff.feature index 33fff685250..101696aa6a2 100644 --- a/fineract-e2e-tests-runner/src/test/resources/features/WorkingCapitalLoanChargeOff.feature +++ b/fineract-e2e-tests-runner/src/test/resources/features/WorkingCapitalLoanChargeOff.feature @@ -450,7 +450,7 @@ Feature: Working Capital Loan Charge-off | 15 January 2026 | Charge-off | 60.0 | 60.0 | 0.0 | 0.0 | true | Then Working Capital loan status will be "CLOSED_OBLIGATIONS_MET" - @TestRailId:TODO_ADD_01 + @TestRailId:C106729 Scenario: Verify Working Capital Charge-off transactions - Backdated discount fee adjustment on a re-charged-off loan should correct realized income # Step 1: WC loan 9000 / total payment volume 100000 / rate 18, approve and disburse on 01 January 2026 with discount 1000. When Admin sets the business date to "01 January 2026" @@ -462,12 +462,12 @@ Feature: Working Capital Loan Charge-off And Admin successfully disburse the Working Capital loan on "01 January 2026" with "9000" EUR transaction amount and "1000" discount amount And Admin loads discount fee transaction from Working Capital loan for adjustment -# Step 2: 02 January 2026 -> repayment 50; run COB (amortization 9.61). +# Step 2: 02 January 2026 -> run COB for 01 January (no amortization); repayment 50. And Admin sets the business date to "02 January 2026" And Admin runs inline COB job for Working Capital Loan by loanId When Customer makes "REPAYMENT" transaction on "02 January 2026" with 50.0 transaction amount on Working Capital loan -# Step 3: 04 January 2026 -> charge off (9950, final amortization 990.39 to charge-off expense). +# Step 3: 04 January 2026 -> run COB (amortization 9.61); charge off (9950, final amortization 990.39 to charge-off expense). And Admin sets the business date to "04 January 2026" And Admin runs inline COB job for Working Capital Loan by loanId When Admin charges off the Working Capital loan on "04 January 2026" @@ -478,7 +478,7 @@ Feature: Working Capital Loan Charge-off When Customer makes "REPAYMENT" transaction on "03 January 2026" with 9950.0 transaction amount on Working Capital loan # Step 5: Undo that repayment (loan ACTIVE, outstanding 9950, not charged off, realized still 1000.00). - When Customer undo "1"th working capital transaction made on "03 January 2026" + When Customer undo "1"th "Repayment" transaction made on "03 January 2026" on Working Capital loan # Step 6: Charge off again on 05 January 2026 (no final amortization, deferred income already 0). When Admin charges off the Working Capital loan on "05 January 2026" @@ -507,6 +507,6 @@ Feature: Working Capital Loan Charge-off And Working Capital loan balance payload contains the following fields: | field | value | | totalDiscountFee | 1000.0 | - | totalDiscountFeeAdjustment | 000.0 | + | totalDiscountFeeAdjustment | 0.0 | | realizedIncome | 1000.0 | | unrealizedIncome | 0.0 | diff --git a/fineract-e2e-tests-runner/src/test/resources/features/WorkingCapitalLoanChargeOffAccounting.feature b/fineract-e2e-tests-runner/src/test/resources/features/WorkingCapitalLoanChargeOffAccounting.feature index 1c3b7bf4286..cc7b4b53e6f 100644 --- a/fineract-e2e-tests-runner/src/test/resources/features/WorkingCapitalLoanChargeOffAccounting.feature +++ b/fineract-e2e-tests-runner/src/test/resources/features/WorkingCapitalLoanChargeOffAccounting.feature @@ -2793,3 +2793,74 @@ Feature: Working Capital Charge-Off Accounting Entries | principal | totalPaidPrincipal | realizedIncome | unrealizedIncome | overpaymentAmount | chargedOff | | 9005.0 | 50.0 | 5.0 | 0.0 | 0.0 | true | Then Admin closes the Working Capital loan with all obligations met with a full repayment on "04 February 2026" + + @TestRailId:C106730 + Scenario: Verify Working Capital charge-off accounting: backdated discount fee adjustment on a re-charged-off loan without a linked final amortization posts the correction to charge-off expense and undo restores it - UC57 + Given Admin sets the business date to "01 January 2026" + And Admin creates a client with random data and creates-approves-disburses a working capital loan with the following data: + | LoanProduct | submittedOnDate | expectedDisbursementDate | principalAmount | totalPayment | periodPaymentRate | discount | + | WCLP_ADVANCED_ACCOUNTING | 01 January 2026 | 01 January 2026 | 9000 | 100000 | 18 | 0 | + And Admin adds Discount fee with "1000" amount on Working Capital loan account for last disbursement + When Admin sets the business date to "02 January 2026" + And Customer makes repayment on "02 January 2026" with 50 transaction amount on Working Capital loan + And Admin sets the business date to "03 January 2026" + And Admin runs inline COB job for Working Capital Loan by loanId + # --- First charge-off: the unreleased discount 990.39 moves to charge-off expense --- # + When Admin sets the business date to "04 January 2026" + And Admin charges off the Working Capital loan on "04 January 2026" + And Working capital loan account has the correct data: + | principal | totalPaidPrincipal | realizedIncome | unrealizedIncome | overpaymentAmount | chargedOff | + | 10000.0 | 50.0 | 1000.0 | 0.0 | 0.0 | true | + # --- Backdated payoff lifts the charge-off and closes the loan; the whole discount is realized as income --- # + When Admin sets the business date to "05 January 2026" + And Customer makes repayment on "03 January 2026" with 9950 transaction amount on Working Capital loan + Then Working Capital loan status will be "CLOSED_OBLIGATIONS_MET" + And Working capital loan account has the correct data: + | principal | totalPaidPrincipal | realizedIncome | unrealizedIncome | overpaymentAmount | chargedOff | + | 10000.0 | 10000.0 | 1000.0 | 0.0 | 0.0 | false | + # --- Undo the payoff and charge off again: deferred income is already 0, so no final amortization is linked to this charge-off --- # + When Customer undo "1"th "Repayment" transaction made on "03 January 2026" on Working Capital loan + Then Working Capital loan status will be "ACTIVE" + And Admin charges off the Working Capital loan on "05 January 2026" + And Working capital loan account has the correct data: + | principal | totalPaidPrincipal | realizedIncome | unrealizedIncome | overpaymentAmount | chargedOff | + | 10000.0 | 50.0 | 1000.0 | 0.0 | 0.0 | true | + # --- Backdated discount fee adjustment: realized income must drop to the net discount even without a linked final amortization --- # + And Admin adds Discount fee adjustment with "100" amount on transaction date "03 January 2026" on Working Capital loan account for last discount + Then Working capital loan account has the correct data: + | principal | totalPaidPrincipal | realizedIncome | unrealizedIncome | overpaymentAmount | chargedOff | + | 9900.0 | 50.0 | 900.0 | 0.0 | 0.0 | true | + Then Working Capital Loan Transactions tab has a "DISCOUNT_FEE_AMORTIZATION_ADJUSTMENT" transaction with date "05 January 2026" which has the following Journal entries: + | Type | Account code | Account name | Debit | Credit | + | EXPENSE | 744007 | Credit Loss/Bad Debt | 100.0 | | + | LIABILITY | 240005 | Deferred Interest Revenue | | 100.0 | + And Working Capital Loan has transactions: + | transactionDate | type | transactionAmount | principalPortion | feeChargesPortion | penaltyChargesPortion | reversed | + | 01 January 2026 | Disbursement | 9000.0 | 9000.0 | 0.0 | 0.0 | false | + | 01 January 2026 | Discount Fee | 1000.0 | 1000.0 | 0.0 | 0.0 | false | + | 02 January 2026 | Repayment | 50.0 | 50.0 | 0.0 | 0.0 | false | + | 02 January 2026 | Discount Fee Amortization | 9.61 | | | | false | + | 03 January 2026 | Repayment | 9950.0 | 9950.0 | 0.0 | 0.0 | true | + | 03 January 2026 | Discount Fee Amortization | 990.39 | | | | false | + | 03 January 2026 | Discount Fee Adjustment | 100.0 | 100.0 | 0.0 | 0.0 | false | + | 04 January 2026 | Charge-off | 9950.0 | 9950.0 | 0.0 | 0.0 | true | + | 04 January 2026 | Discount Fee Amortization | 990.39 | | | | true | + | 05 January 2026 | Charge-off | 9850.0 | 9850.0 | 0.0 | 0.0 | false | + | 05 January 2026 | Discount Fee Amortization Adjustment | 100.0 | | | | false | + # --- Later COB runs change nothing on the charged-off loan --- # + When Admin sets the business date to "07 January 2026" + And Admin runs inline COB job for Working Capital Loan by loanId + And Working capital loan account has the correct data: + | principal | totalPaidPrincipal | realizedIncome | unrealizedIncome | overpaymentAmount | chargedOff | + | 9900.0 | 50.0 | 900.0 | 0.0 | 0.0 | true | + # --- Undo of the adjustment restores the previous state --- # + When Admin undo the Discount fee adjustment with "100.0" amount on Working Capital loan account + Then Working capital loan account has the correct data: + | principal | totalPaidPrincipal | realizedIncome | unrealizedIncome | overpaymentAmount | chargedOff | + | 10000.0 | 50.0 | 1000.0 | 0.0 | 0.0 | true | + Then Working Capital Loan Transactions tab has a reversed "DISCOUNT_FEE_AMORTIZATION_ADJUSTMENT" transaction with date "05 January 2026" which has the following Journal entries: + | Type | Account code | Account name | Debit | Credit | + | EXPENSE | 744007 | Credit Loss/Bad Debt | 100.0 | | + | LIABILITY | 240005 | Deferred Interest Revenue | | 100.0 | + | EXPENSE | 744007 | Credit Loss/Bad Debt | | 100.0 | + | LIABILITY | 240005 | Deferred Interest Revenue | 100.0 | |