This is an automated email from the ASF dual-hosted git repository.

ptuomola 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 9ad6694  Block transfer between different currencies (FINERACT-1355)
9ad6694 is described below

commit 9ad66940219cc878ae89888c634a5caddc898066
Author: ebouvard <[email protected]>
AuthorDate: Tue Jun 1 17:53:02 2021 +0200

    Block transfer between different currencies (FINERACT-1355)
---
 .../exception/DifferentCurrenciesException.java    | 28 ++++++++++++++++++++++
 .../AccountTransfersWritePlatformServiceImpl.java  |  6 +++++
 2 files changed, 34 insertions(+)

diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/exception/DifferentCurrenciesException.java
 
b/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/exception/DifferentCurrenciesException.java
new file mode 100644
index 0000000..7514b32
--- /dev/null
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/exception/DifferentCurrenciesException.java
@@ -0,0 +1,28 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.portfolio.account.exception;
+
+import 
org.apache.fineract.infrastructure.core.exception.AbstractPlatformDomainRuleException;
+
+public class DifferentCurrenciesException extends 
AbstractPlatformDomainRuleException {
+
+    public DifferentCurrenciesException(final String currency1, final String 
currency2) {
+        super("error.msg.accounttransfer.different.currencies", "Trying to 
transfer from " + currency1 + " to " + currency2);
+    }
+}
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/service/AccountTransfersWritePlatformServiceImpl.java
 
b/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/service/AccountTransfersWritePlatformServiceImpl.java
index de6d272..664d772 100644
--- 
a/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/service/AccountTransfersWritePlatformServiceImpl.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/service/AccountTransfersWritePlatformServiceImpl.java
@@ -44,6 +44,7 @@ import 
org.apache.fineract.portfolio.account.domain.AccountTransferDetails;
 import org.apache.fineract.portfolio.account.domain.AccountTransferRepository;
 import org.apache.fineract.portfolio.account.domain.AccountTransferTransaction;
 import org.apache.fineract.portfolio.account.domain.AccountTransferType;
+import 
org.apache.fineract.portfolio.account.exception.DifferentCurrenciesException;
 import org.apache.fineract.portfolio.loanaccount.data.HolidayDetailDTO;
 import org.apache.fineract.portfolio.loanaccount.domain.Loan;
 import 
org.apache.fineract.portfolio.loanaccount.domain.LoanAccountDomainService;
@@ -144,6 +145,11 @@ public class AccountTransfersWritePlatformServiceImpl 
implements AccountTransfer
             final SavingsAccountTransaction deposit = 
this.savingsAccountDomainService.handleDeposit(toSavingsAccount, fmt, 
transactionDate,
                     transactionAmount, paymentDetail, isAccountTransfer, 
isRegularTransaction);
 
+            if 
(!fromSavingsAccount.getCurrency().getCode().equals(toSavingsAccount.getCurrency().getCode()))
 {
+                throw new 
DifferentCurrenciesException(fromSavingsAccount.getCurrency().getCode(),
+                        toSavingsAccount.getCurrency().getCode());
+            }
+
             final AccountTransferDetails accountTransferDetails = 
this.accountTransferAssembler.assembleSavingsToSavingsTransfer(command,
                     fromSavingsAccount, toSavingsAccount, withdrawal, deposit);
             
this.accountTransferDetailRepository.saveAndFlush(accountTransferDetails);

Reply via email to