This is an automated email from the ASF dual-hosted git repository.
vorburger pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract.git
The following commit(s) were added to refs/heads/develop by this push:
new 0474f59 fix overdraft account balance (PR #659 for FINERACT-753)
0474f59 is described below
commit 0474f59bcfd9a3a0bb32f870a9a5da1fc1e32bd3
Author: andrew-dzak <[email protected]>
AuthorDate: Wed Dec 11 07:59:50 2019 +0100
fix overdraft account balance (PR #659 for FINERACT-753)
---
.../ClientSavingsIntegrationTest.java | 71 ++++++++++++++++++++++
.../common/savings/SavingsAccountHelper.java | 16 +++++
.../portfolio/savings/domain/SavingsAccount.java | 9 +++
3 files changed, 96 insertions(+)
diff --git
a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/ClientSavingsIntegrationTest.java
b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/ClientSavingsIntegrationTest.java
index fe7b4c2..fc56a58 100755
---
a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/ClientSavingsIntegrationTest.java
+++
b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/ClientSavingsIntegrationTest.java
@@ -44,6 +44,7 @@ import
org.apache.fineract.integrationtests.common.charges.ChargesHelper;
import
org.apache.fineract.integrationtests.common.savings.SavingsAccountHelper;
import
org.apache.fineract.integrationtests.common.savings.SavingsProductHelper;
import
org.apache.fineract.integrationtests.common.savings.SavingsStatusChecker;
+import org.apache.fineract.portfolio.charge.domain.ChargeTimeType;
import org.joda.time.LocalDate;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
@@ -2233,4 +2234,74 @@ public class ClientSavingsIntegrationTest {
assertEquals("Verifying Withdrawal Amount", new Float("300"),
withdrawTransaction.get("amount"));
}
+
+ /**
+ * incorrect savings account balance when charge transaction is
+ * reversed during an overdraft recalculate Daily Balances
+ */
+
+ @Test
+ public void testAccountBalanceAfterTransactionReversal() {
+ this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec,
this.responseSpec);
+ SavingsAccountHelper savingsAccountHelperValidationError = new
SavingsAccountHelper(this.requestSpec,
+ new ResponseSpecBuilder().build());
+
+ final Integer clientID = ClientHelper.createClient(this.requestSpec,
this.responseSpec);
+ Assert.assertNotNull(clientID);
+ final String minBalanceForInterestCalculation = null;
+ final String minRequiredBalance = "500";
+ final String enforceMinRequiredBalance = "false";
+ final boolean allowOverdraft = true;
+ final String MINIMUM_OPENING_BALANCE = "0";
+
+ final Integer savingsProductID =
createSavingsProduct(this.requestSpec, this.responseSpec,
MINIMUM_OPENING_BALANCE,
+ minBalanceForInterestCalculation, minRequiredBalance,
enforceMinRequiredBalance, allowOverdraft);
+ Assert.assertNotNull(savingsProductID);
+
+
+ final Integer savingsId =
this.savingsAccountHelper.applyForSavingsApplication(clientID,
savingsProductID, ACCOUNT_TYPE_INDIVIDUAL);
+ Assert.assertNotNull(savingsId);
+
+
+ HashMap savingsStatusHashMap =
this.savingsAccountHelper.approveSavings(savingsId);
+ SavingsStatusChecker.verifySavingsIsApproved(savingsStatusHashMap);
+
+ savingsStatusHashMap =
this.savingsAccountHelper.activateSavings(savingsId);
+ SavingsStatusChecker.verifySavingsIsActive(savingsStatusHashMap);
+
+
+ Integer depositTransactionId = (Integer)
this.savingsAccountHelper.depositToSavingsAccount(savingsId, "500",
+ SavingsAccountHelper.TRANSACTION_DATE,
CommonConstants.RESPONSE_RESOURCE_ID);
+
+
+ String chargeAmount = "300";
+ String chargeCurrency = "USD";
+
+ final Integer savingsChargeId =
ChargesHelper.createCharges(this.requestSpec, this.responseSpec,
+ ChargesHelper.getSavingsJSON(chargeAmount, chargeCurrency,
ChargeTimeType.SPECIFIED_DUE_DATE));
+
+ Assert.assertNotNull(savingsChargeId);
+
+ Integer amount = 300;
+
+
+ final Integer chargeId =
this.savingsAccountHelper.addChargesForSavingsWithDueDate(savingsId,
savingsChargeId, SavingsAccountHelper.TRANSACTION_DATE,
+ amount);
+
+ Assert.assertNotNull(chargeId);
+
+ final Integer payChargeId =
this.savingsAccountHelper.payCharge(chargeId, savingsId, chargeAmount,
SavingsAccountHelper.TRANSACTION_DATE);
+
+
+ final Integer undoSavingsTransaction =
this.savingsAccountHelper.undoSavingsAccountTransaction(savingsId,
depositTransactionId);
+ HashMap reversedDepositTransaction =
this.savingsAccountHelper.getSavingsTransaction(savingsId,
depositTransactionId);
+ Assert.assertTrue((Boolean)
reversedDepositTransaction.get("reversed"));
+
+ HashMap summary =
this.savingsAccountHelper.getSavingsSummary(savingsId);
+
+ Float balance = new Float("-300");
+
+ assertEquals("Verifying opening Balance is -300", balance,
summary.get("accountBalance"));
+
+ }
}
\ No newline at end of file
diff --git
a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/savings/SavingsAccountHelper.java
b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/savings/SavingsAccountHelper.java
index ddb53cb..f434203 100644
---
a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/savings/SavingsAccountHelper.java
+++
b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/savings/SavingsAccountHelper.java
@@ -269,6 +269,11 @@ public class SavingsAccountHelper {
getPeriodChargeRequestJSON(chargeId, addDueDate, amount),
CommonConstants.RESPONSE_RESOURCE_ID);
}
+ public Integer addChargesForSavingsWithDueDate(final Integer savingsId,
final Integer chargeId, String addDueDate,Integer amount) {
+ return (Integer) performSavingActions(SAVINGS_ACCOUNT_URL + "/" +
savingsId + "/charges?" + Utils.TENANT_IDENTIFIER,
+ getPeriodChargeRequestJSONWithDueDate(chargeId, addDueDate,
amount), CommonConstants.RESPONSE_RESOURCE_ID);
+ }
+
public Integer payCharge(final Integer chargeId, final Integer savingsId,
String amount, String dueDate) {
return (Integer) performSavingActions(createChargesURL("paycharge",
savingsId, chargeId), getSavingsPayChargeJSON(amount, dueDate),
CommonConstants.RESPONSE_RESOURCE_ID);
@@ -593,6 +598,17 @@ public class SavingsAccountHelper {
return json;
}
+ private String getPeriodChargeRequestJSONWithDueDate(Integer chargeId,
String addDueDate, Integer amount) {
+ final HashMap<String, Object> map = new HashMap<>();
+ map.put("chargeId", chargeId);
+ map.put("amount", amount);
+ map.put("locale", CommonConstants.locale);
+ map.put("dateFormat", "dd MMMM yyy");
+ map.put("dueDate", addDueDate);
+ String json = new Gson().toJson(map);
+ return json;
+ }
+
private String getAccountActivationJSON(final String activationDate) {
final HashMap<String, Object> map = new HashMap<>();
map.put("locale", CommonConstants.locale);
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 ea5fa82..d4f3842 100755
---
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
@@ -851,6 +851,15 @@ public class SavingsAccount extends
AbstractPersistableCustom<Long> {
transaction.updateOverdraftAmount(overdraftAmount.getAmount());
} else if
(overdraftAmount.isNotEqualTo(transaction.getOverdraftAmount(getCurrency()))) {
SavingsAccountTransaction accountTransaction =
SavingsAccountTransaction.copyTransaction(transaction);
+ if(transaction.isChargeTransaction()){
+ Set<SavingsAccountChargePaidBy> chargesPaidBy =
transaction.getSavingsAccountChargesPaid();
+ final Set<SavingsAccountChargePaidBy> newChargePaidBy
= new HashSet<>();
+ chargesPaidBy.forEach(x->
+
newChargePaidBy.add(SavingsAccountChargePaidBy.instance(accountTransaction,x.getSavingsAccountCharge(),
+ x.getAmount()))
+ );
+
accountTransaction.getSavingsAccountChargesPaid().addAll(newChargePaidBy);
+ }
transaction.reverse();
if (overdraftAmount.isGreaterThanZero()) {
accountTransaction.updateOverdraftAmount(overdraftAmount.getAmount());