From 2479dd12898839fb4cef701abf438617fcaa5233 Mon Sep 17 00:00:00 2001 From: logoutdhaval <100835289+logoutdhaval@users.noreply.github.com> Date: Thu, 25 Aug 2022 18:04:22 +0530 Subject: [PATCH] Error with withdraw/deposit transactions after initiating hold transaction (#2540) Co-authored-by: Dhaval Maniyar --- .../savings/domain/SavingsAccount.java | 2 +- .../ClientSavingsIntegrationTest.java | 45 +++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccount.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccount.java index 6fac36276..f5ab802ab 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccount.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccount.java @@ -1015,7 +1015,7 @@ public class SavingsAccount extends AbstractPersistableCustom { if (!transaction.getRunningBalance(transactionAmount.getCurrency()).isEqualTo(transactionAmount)) { transaction.updateRunningBalance(runningBalance); } - if (overdraftAmount.isZero() && runningBalance.isLessThanZero()) { + if (overdraftAmount.isZero() && runningBalance.isLessThanZero() && !transaction.isAmountOnHold()) { overdraftAmount = overdraftAmount.plus(runningBalance.getAmount().negate()); } if (transaction.getId() == null && overdraftAmount.isGreaterThanZero()) { diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/ClientSavingsIntegrationTest.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/ClientSavingsIntegrationTest.java index 5e5b65551..ad1d4d1bb 100644 --- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/ClientSavingsIntegrationTest.java +++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/ClientSavingsIntegrationTest.java @@ -3114,6 +3114,51 @@ public class ClientSavingsIntegrationTest { Assertions.assertFalse(reversalFlag); } + @Test + public void testSavingsAccountDepositAfterHoldAmount() { + this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec); + final ResponseSpecification errorResponse = new ResponseSpecBuilder().expectStatusCode(403).build(); + final SavingsAccountHelper validationErrorHelper = new SavingsAccountHelper(this.requestSpec, errorResponse); + + final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec); + ClientHelper.verifyClientCreatedOnServer(this.requestSpec, this.responseSpec, clientID); + + final String minBalanceForInterestCalculation = null; + final boolean enforceMinRequiredBalance = false; + final boolean allowOverdraft = true; + final boolean lienAllowed = false; + + final Integer savingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, "0", minBalanceForInterestCalculation, + enforceMinRequiredBalance, allowOverdraft, lienAllowed); + Assertions.assertNotNull(savingsProductID); + + final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(clientID, savingsProductID, ACCOUNT_TYPE_INDIVIDUAL); + Assertions.assertNotNull(savingsProductID); + + HashMap savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, savingsId); + SavingsStatusChecker.verifySavingsIsPending(savingsStatusHashMap); + + savingsStatusHashMap = this.savingsAccountHelper.approveSavings(savingsId); + SavingsStatusChecker.verifySavingsIsApproved(savingsStatusHashMap); + + savingsStatusHashMap = this.savingsAccountHelper.activateSavings(savingsId); + SavingsStatusChecker.verifySavingsIsActive(savingsStatusHashMap); + + this.savingsAccountHelper.holdAmountInSavingsAccount(savingsId, "100", lienAllowed, SavingsAccountHelper.TRANSACTION_DATE, + CommonConstants.RESPONSE_RESOURCE_ID); + + Integer depositTransactionId = (Integer) this.savingsAccountHelper.depositToSavingsAccount(savingsId, "200", + SavingsAccountHelper.TRANSACTION_DATE, CommonConstants.RESPONSE_RESOURCE_ID); + + Assertions.assertNotNull(depositTransactionId); + List error = (List) validationErrorHelper.withdrawalFromSavingsAccount(savingsId, "200", + SavingsAccountHelper.TRANSACTION_DATE, CommonConstants.RESPONSE_ERROR); + + assertEquals("error.msg.savingsaccount.transaction.insufficient.account.balance", + error.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE)); + + } + private Integer createSavingsAccountDailyPostingOverdraft(final Integer clientID, final String startDate) { final Integer savingsProductID = createSavingsProductDailyPostingOverdraft(); Assertions.assertNotNull(savingsProductID);