savings charge currency must match savings account currency
This commit is contained in:
-3
@@ -336,9 +336,6 @@ public class SavingsAccount extends AbstractPersistable<Long> {
|
||||
|
||||
if (!CollectionUtils.isEmpty(savingsAccountCharges)) {
|
||||
this.charges = associateChargesWithThisSavingsAccount(savingsAccountCharges);
|
||||
// TODO:Add charges details to savings summary
|
||||
// this.summary =
|
||||
// updateSummaryWithTotalFeeChargesDueAtDisbursement(deriveSumTotalOfChargesDueAtDisbursement());
|
||||
}
|
||||
|
||||
this.summary = new SavingsAccountSummary();
|
||||
|
||||
+1
-1
@@ -236,7 +236,7 @@ public class SavingsAccountAssembler {
|
||||
monthDayOfAnnualFee = product.monthDayOfAnnualFee();
|
||||
}
|
||||
|
||||
final Set<SavingsAccountCharge> charges = this.savingsAccountChargeAssembler.fromParsedJson(element);
|
||||
final Set<SavingsAccountCharge> charges = this.savingsAccountChargeAssembler.fromParsedJson(element, product.currency().getCode());
|
||||
|
||||
final SavingsAccount account = SavingsAccount.createNewApplicationForSubmittal(client, group, product, fieldOfficer, accountNo,
|
||||
externalId, accountType, submittedOnDate, interestRate, interestCompoundingPeriodType, interestPostingPeriodType,
|
||||
|
||||
+5
@@ -505,6 +505,11 @@ public class SavingsAccountCharge extends AbstractPersistable<Long> {
|
||||
public SavingsAccount savingsAccount(){
|
||||
return this.savingsAccount;
|
||||
}
|
||||
|
||||
public boolean hasCurrencyCodeOf(final String matchingCurrencyCode) {
|
||||
if (this.currencyCode() == null || matchingCurrencyCode == null) { return false; }
|
||||
return this.currencyCode().equalsIgnoreCase(matchingCurrencyCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
|
||||
+21
-1
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
package org.mifosplatform.portfolio.savings.domain;
|
||||
|
||||
import static org.mifosplatform.portfolio.savings.SavingsApiConstants.SAVINGS_ACCOUNT_RESOURCE_NAME;
|
||||
import static org.mifosplatform.portfolio.savings.SavingsApiConstants.amountParamName;
|
||||
import static org.mifosplatform.portfolio.savings.SavingsApiConstants.chargeCalculationTypeParamName;
|
||||
import static org.mifosplatform.portfolio.savings.SavingsApiConstants.chargeIdParamName;
|
||||
@@ -14,11 +15,16 @@ import static org.mifosplatform.portfolio.savings.SavingsApiConstants.dueAsOfDat
|
||||
import static org.mifosplatform.portfolio.savings.SavingsApiConstants.idParamName;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
import org.joda.time.LocalDate;
|
||||
import org.mifosplatform.infrastructure.core.data.ApiParameterError;
|
||||
import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder;
|
||||
import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException;
|
||||
import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper;
|
||||
import org.mifosplatform.portfolio.charge.domain.Charge;
|
||||
import org.mifosplatform.portfolio.charge.domain.ChargeCalculationType;
|
||||
@@ -48,7 +54,7 @@ public class SavingsAccountChargeAssembler {
|
||||
this.savingsAccountChargeRepository = savingsAccountChargeRepository;
|
||||
}
|
||||
|
||||
public Set<SavingsAccountCharge> fromParsedJson(final JsonElement element) {
|
||||
public Set<SavingsAccountCharge> fromParsedJson(final JsonElement element, final String productCurrencyCode) {
|
||||
|
||||
final Set<SavingsAccountCharge> savingsAccountCharges = new HashSet<SavingsAccountCharge>();
|
||||
|
||||
@@ -106,6 +112,20 @@ public class SavingsAccountChargeAssembler {
|
||||
}
|
||||
}
|
||||
|
||||
this.validateSavingsCharges(savingsAccountCharges, productCurrencyCode);
|
||||
return savingsAccountCharges;
|
||||
}
|
||||
|
||||
private void validateSavingsCharges(final Set<SavingsAccountCharge> charges, final String productCurrencyCode) {
|
||||
final List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
|
||||
.resource(SAVINGS_ACCOUNT_RESOURCE_NAME);
|
||||
for (SavingsAccountCharge savingsAccountCharge : charges) {
|
||||
if(!savingsAccountCharge.hasCurrencyCodeOf(productCurrencyCode)){
|
||||
baseDataValidator.reset().parameter("currency").value(savingsAccountCharge.getCharge().getId())
|
||||
.failWithCodeNoParameterAddedToErrorCode("currency.and.charge.currency.not.same");
|
||||
}
|
||||
}
|
||||
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); }
|
||||
}
|
||||
}
|
||||
+1
-4
@@ -233,10 +233,7 @@ public class SavingsApplicationProcessWritePlatformServiceJpaRepositoryImpl impl
|
||||
}
|
||||
|
||||
if (changes.containsKey("charges")) {
|
||||
// final Set<Charge> savingsProductCharges =
|
||||
// this.savi.assembleListOfSavingsProductCharges(command,
|
||||
// product.currency().getCode());
|
||||
final Set<SavingsAccountCharge> charges = this.savingsAccountChargeAssembler.fromParsedJson(command.parsedJson());
|
||||
final Set<SavingsAccountCharge> charges = this.savingsAccountChargeAssembler.fromParsedJson(command.parsedJson(), account.getCurrency().getCode());
|
||||
final boolean updated = account.update(charges);
|
||||
if (!updated) {
|
||||
changes.remove("charges");
|
||||
|
||||
Reference in New Issue
Block a user