From 9ad66940219cc878ae89888c634a5caddc898066 Mon Sep 17 00:00:00 2001 From: ebouvard Date: Tue, 1 Jun 2021 17:53:02 +0200 Subject: [PATCH] Block transfer between different currencies (FINERACT-1355) --- .../DifferentCurrenciesException.java | 28 +++++++++++++++++++ ...ountTransfersWritePlatformServiceImpl.java | 6 ++++ 2 files changed, 34 insertions(+) create mode 100644 fineract-provider/src/main/java/org/apache/fineract/portfolio/account/exception/DifferentCurrenciesException.java 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 000000000..7514b32f2 --- /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 de6d27229..664d772cb 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);