Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,24 @@ public void undoAccountTransfer() {
ok(() -> fineractClient.accountTransfers().accountTransferOperation(response.getResourceId(), "undo"));
}

@When("Initiate account transfer from loan to savings on {string} for {double}")
public void initiateLoanToSavingsTransfer(String date, double amount) {
PostClientsResponse clientResponse = testContext().get(TestContextKey.CLIENT_CREATE_RESPONSE);
long clientId = clientResponse.getClientId();
long savingsId = ((PostSavingsAccountsResponse) testContext().get(TestContextKey.EUR_SAVINGS_ACCOUNT_CREATE_RESPONSE))
.getSavingsId();
long loanId = ((PostLoansResponse) testContext().get(TestContextKey.LOAN_CREATE_RESPONSE)).getLoanId();

AccountTransferRequest request = new AccountTransferRequest().fromClientId(String.valueOf(clientId))
.fromAccountId(String.valueOf(loanId)).fromAccountType(LOAN_ACCOUNT_TYPE).fromOfficeId("1")
.toClientId(String.valueOf(clientId)).toAccountId(String.valueOf(savingsId)).toAccountType(SAVINGS_ACCOUNT_TYPE)
.toOfficeId("1").transferDate(date).transferAmount(String.valueOf(amount)).transferDescription("Transfer")
.dateFormat(DATE_FORMAT).locale(DEFAULT_LOCALE);

PostAccountTransfersResponse response = ok(() -> fineractClient.accountTransfers().createAccountTransfer(request));
testContext().set("accountTransferResponse", response);
}

@When("Undo the last account transfer it fails with error: it is already reverted")
public void undoAccountTransferFail() {
PostAccountTransfersResponse response = testContext().get("accountTransferResponse");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,46 @@ Feature: AccountTransfer
| 02 May 2026 | Repayment | 10.0 | 10.0 | 0.0 | 0.0 | 0.0 | 990.0 | true | false |
When Undo the last account transfer it fails with error: it is already reverted

@TestRailId:C80938
Scenario: Transfer from loan to savings then undo it
When Admin sets the business date to "13 May 2026"
And Admin creates a client with random data
And Admin creates a EUR savings product
And Client creates a new EUR savings account with "01 May 2026" submitted on date
And Approve EUR savings account on "01 May 2026" date
And Activate EUR savings account on "01 May 2026" date
And Client successfully deposits 1000 EUR to the savings account on "01 May 2026" date
Then Savings Transactions tab has the following data:
| Transaction date | Transaction Type | Amount | Balance |
| 01 May 2026 | Deposit | 1000.0 | 1000.0 |
When Admin creates a fully customized loan with the following data:
| LoanProduct | submitted on date | with Principal | ANNUAL interest rate % | interest type | interest calculation period | amortization type | loanTermFrequency | loanTermFrequencyType | repaymentEvery | repaymentFrequencyType | numberOfRepayments | graceOnPrincipalPayment | graceOnInterestPayment | interest free period | Payment strategy |
| LP2_ADV_PYMNT_INTEREST_DAILY_EMI_360_30 | 01 May 2026 | 1000 | 12 | DECLINING_BALANCE | DAILY | EQUAL_INSTALLMENTS | 6 | MONTHS | 1 | MONTHS | 6 | 0 | 0 | 0 | ADVANCED_PAYMENT_ALLOCATION |
And Admin successfully approves the loan on "01 May 2026" with "1000" amount and expected disbursement date on "01 May 2026"
When Admin successfully disburse the loan on "01 May 2026" with "1000" EUR transaction amount
And Customer makes "AUTOPAY" repayment on "02 May 2026" with 1010 EUR transaction amount
When Initiate account transfer from loan to savings on "2 May 2026" for 10
Then Savings Transactions tab has the following data:
| Transaction date | Transaction Type | Amount | Balance |
| 01 May 2026 | Deposit | 1000.0 | 1000.0 |
| 02 May 2026 | Deposit | 10.0 | 1010.0 |
Then Loan Transactions tab has the following data:
| Transaction date | Transaction Type | Amount | Principal | Interest | Fees | Penalties | Loan Balance | Reverted | Replayed |
| 01 May 2026 | Disbursement | 1000.0 | 0.0 | 0.0 | 0.0 | 0.0 | 1000.0 | false | false |
| 02 May 2026 | Repayment | 1010.0 | 1000.0 | 0.0 | 0.0 | 0.0 | 0.0 | false | false |
| 02 May 2026 | Refund | 10.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | false | false |
When Undo the last account transfer
Then Savings Transactions tab has the following data:
| Transaction date | Transaction Type | Amount | Balance | Reverted |
| 01 May 2026 | Deposit | 1000.0 | 1000.0 | false |
| 02 May 2026 | Deposit | 10.0 | 0.0 | true |
Then Loan Transactions tab has the following data:
| Transaction date | Transaction Type | Amount | Principal | Interest | Fees | Penalties | Loan Balance | Reverted | Replayed |
| 01 May 2026 | Disbursement | 1000.0 | 0.0 | 0.0 | 0.0 | 0.0 | 1000.0 | false | false |
| 02 May 2026 | Repayment | 1010.0 | 1000.0 | 0.0 | 0.0 | 0.0 | 0.0 | false | false |
| 02 May 2026 | Refund | 10.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | true | false |
When Undo the last account transfer it fails with error: it is already reverted

@TestRailId:C80967
Scenario: Transfer between savings accounts
When Admin sets the business date to "13 May 2026"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,12 @@ public CommandProcessingResult undo(JsonCommand command) {
transaction.reverse();
});
} else if (isLoanToSavingsAccountTransfer(fromAccountType, toAccountType)) {
throw new UnsupportedOperationException("Undo Loan to Savings Account Transfer is not implemented");
accountTransferDetails.getAccountTransferTransactions().forEach(transaction -> {
this.savingsAccountWritePlatformService.undoTransaction(transaction.getToSavingsTransaction().getSavingsAccount().getId(),
transaction.getToSavingsTransaction().getId(), true);
this.loanAccountDomainService.reverseTransfer(transaction.getFromLoanTransaction());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use

LoanAdjustmentParameter parameter = LoanAdjustmentParameter.builder().transactionAmount(BigDecimal.ZERO)
                        .paymentDetail(paymentDetail).transactionDate(transaction.getToLoanTransaction().getTransactionDate())
                        .txnExternalId(transaction.getToLoanTransaction().getExternalId()).reversalTxnExternalId(reversalTxnExternalId)
                        .noteText(null).build();
                this.loanAdjustmentService.adjustLoanTransaction(transaction.getToLoanTransaction().getLoan(),
                        transaction.getToLoanTransaction(), parameter, null, new HashMap<>());

Which is more complete and thorough on reversal of loan transaction

transaction.reverse();
});
}

final CommandProcessingResultBuilder builder = new CommandProcessingResultBuilder() //
Expand Down
Loading