FINERACT-2326: Charges with Tax group Id ignored

This commit is contained in:
Jose Alberto Hernandez
2025-08-13 13:58:21 +02:00
committed by Adam Saghy
parent c55cfe9d08
commit 33fae09afb
9 changed files with 78 additions and 31 deletions
@@ -96,6 +96,16 @@ final class ChargesApiResourceSwagger {
public String description;
}
static final class GetChargesTaxGroup {
private GetChargesTaxGroup() {}
@Schema(example = "1")
public Long id;
@Schema(example = "tax")
public String name;
}
@Schema(example = "1")
public Long id;
@Schema(example = "Loan Service fee")
@@ -113,6 +123,7 @@ final class ChargesApiResourceSwagger {
public GetChargesPaymentModeResponse chargePaymentMode;
public BigDecimal minCap;
public BigDecimal maxCap;
public GetChargesTaxGroup taxGroup;
}
@Schema(description = "PostChargesRequest")
@@ -146,6 +157,8 @@ final class ChargesApiResourceSwagger {
public BigDecimal minCap;
@Schema(example = "45.56")
public BigDecimal maxCap;
@Schema(example = "1")
public Long taxGroupId;
}
@Schema(description = "PostChargesResponse")
@@ -206,6 +219,8 @@ final class ChargesApiResourceSwagger {
public BigDecimal minCap;
@Schema(example = "120.0")
public BigDecimal maxCap;
@Schema(example = "1")
public Long taxGroupId;
}
@Schema(description = "PutChargesChargeIdResponse")
@@ -18,30 +18,25 @@
*/
package org.apache.fineract.portfolio.charge.handler;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.commands.annotation.CommandType;
import org.apache.fineract.commands.handler.NewCommandSourceHandler;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.portfolio.charge.service.ChargeWritePlatformService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@RequiredArgsConstructor
@Service
@CommandType(entity = "CHARGE", action = "CREATE")
public class CreateChargeDefinitionCommandHandler implements NewCommandSourceHandler {
private final ChargeWritePlatformService clientWritePlatformService;
@Autowired
public CreateChargeDefinitionCommandHandler(final ChargeWritePlatformService clientWritePlatformService) {
this.clientWritePlatformService = clientWritePlatformService;
}
@Transactional
@Override
public CommandProcessingResult processCommand(final JsonCommand command) {
return this.clientWritePlatformService.createCharge(command);
}
}
@@ -18,30 +18,25 @@
*/
package org.apache.fineract.portfolio.charge.handler;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.commands.annotation.CommandType;
import org.apache.fineract.commands.handler.NewCommandSourceHandler;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.portfolio.charge.service.ChargeWritePlatformService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@RequiredArgsConstructor
@Service
@CommandType(entity = "CHARGE", action = "DELETE")
public class DeleteChargeDefinitionCommandHandler implements NewCommandSourceHandler {
private final ChargeWritePlatformService clientWritePlatformService;
@Autowired
public DeleteChargeDefinitionCommandHandler(final ChargeWritePlatformService clientWritePlatformService) {
this.clientWritePlatformService = clientWritePlatformService;
}
@Transactional
@Override
public CommandProcessingResult processCommand(final JsonCommand command) {
return this.clientWritePlatformService.deleteCharge(command.entityId());
}
}
@@ -18,30 +18,25 @@
*/
package org.apache.fineract.portfolio.charge.handler;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.commands.annotation.CommandType;
import org.apache.fineract.commands.handler.NewCommandSourceHandler;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.portfolio.charge.service.ChargeWritePlatformService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@RequiredArgsConstructor
@Service
@CommandType(entity = "CHARGE", action = "UPDATE")
public class UpdateChargeDefinitionCommandHandler implements NewCommandSourceHandler {
private final ChargeWritePlatformService clientWritePlatformService;
@Autowired
public UpdateChargeDefinitionCommandHandler(final ChargeWritePlatformService clientWritePlatformService) {
this.clientWritePlatformService = clientWritePlatformService;
}
@Transactional
@Override
public CommandProcessingResult processCommand(final JsonCommand command) {
return this.clientWritePlatformService.updateCharge(command.entityId(), command);
}
}
@@ -51,5 +51,6 @@ public class ChargeRequest implements Serializable {
private Boolean enablePaymentType;
private BigDecimal minCap;
private BigDecimal maxCap;
private Long taxGroupId;
}
@@ -27,9 +27,18 @@ import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import org.apache.fineract.client.models.ChargeRequest;
import org.apache.fineract.client.models.GetChargesResponse;
import org.apache.fineract.client.models.PostChargesResponse;
import org.apache.fineract.client.models.PostTaxesComponentsRequest;
import org.apache.fineract.client.models.PostTaxesComponentsResponse;
import org.apache.fineract.client.models.PostTaxesGroupRequest;
import org.apache.fineract.client.models.PostTaxesGroupResponse;
import org.apache.fineract.client.models.PostTaxesGroupTaxComponents;
import org.apache.fineract.integrationtests.common.TaxComponentHelper;
import org.apache.fineract.integrationtests.common.TaxGroupHelper;
import org.apache.fineract.integrationtests.common.Utils;
import org.apache.fineract.integrationtests.common.charges.ChargesHelper;
import org.apache.fineract.portfolio.charge.domain.ChargeCalculationType;
@@ -352,4 +361,39 @@ public class ChargesTest {
Assertions.assertEquals(maxCapVal.stripTrailingZeros(), chargeResponseData.getMaxCap().stripTrailingZeros());
}
@Test
public void testChargeCreationWithTaxGroup() {
final ChargesHelper chargesHelper = new ChargesHelper();
final PostTaxesComponentsRequest taxComponentRequest = new PostTaxesComponentsRequest()
.name(Utils.randomStringGenerator("TAX_COM_", 4)).percentage(12.0f).startDate("01 January 2023").dateFormat("dd MMMM yyyy")
.locale("en");
final PostTaxesComponentsResponse taxComponentRespose = TaxComponentHelper.createTaxComponent(taxComponentRequest);
Assertions.assertNotNull(taxComponentRequest);
final Set<PostTaxesGroupTaxComponents> taxComponentsSet = new HashSet<>();
taxComponentsSet
.add(new PostTaxesGroupTaxComponents().taxComponentId(taxComponentRespose.getResourceId()).startDate("01 January 2023"));
final PostTaxesGroupRequest taxGroupRequest = new PostTaxesGroupRequest().name(Utils.randomStringGenerator("TAX_GRP_", 4))
.taxComponents(taxComponentsSet).dateFormat("dd MMMM yyyy").locale("en");
final PostTaxesGroupResponse taxGroupResponse = TaxGroupHelper.createTaxGroup(taxGroupRequest);
Assertions.assertNotNull(taxGroupResponse);
final PostChargesResponse feeCharge = chargesHelper.createCharges(
new ChargeRequest().penalty(false).amount(9.0).chargeCalculationType(ChargeCalculationType.PERCENT_OF_AMOUNT.getValue())
.chargeTimeType(ChargeTimeType.DISBURSEMENT.getValue()).chargePaymentMode(ChargePaymentMode.REGULAR.getValue())
.currencyCode("USD").name(Utils.randomStringGenerator("FEE_" + Calendar.getInstance().getTimeInMillis(), 5))
.chargeAppliesTo(1).locale("en").active(true).taxGroupId(taxGroupResponse.getResourceId()));
Assertions.assertNotNull(feeCharge);
final Long chargeId = feeCharge.getResourceId();
Assertions.assertNotNull(chargeId);
final GetChargesResponse chargeResponseData = chargesHelper.retrieveCharge(chargeId);
Assertions.assertNotNull(chargeResponseData);
Assertions.assertNotNull(chargeResponseData.getTaxGroup());
Assertions.assertEquals(chargeResponseData.getTaxGroup().getId(), taxGroupResponse.getResourceId());
}
}
@@ -22,6 +22,9 @@ import com.google.gson.Gson;
import io.restassured.specification.RequestSpecification;
import io.restassured.specification.ResponseSpecification;
import java.util.HashMap;
import org.apache.fineract.client.models.PostTaxesComponentsRequest;
import org.apache.fineract.client.models.PostTaxesComponentsResponse;
import org.apache.fineract.client.util.Calls;
import org.apache.fineract.integrationtests.common.accounting.Account;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -66,7 +69,7 @@ public final class TaxComponentHelper {
@Deprecated(forRemoval = true)
public static HashMap<String, String> getBasicTaxComponentMap(final String percentage) {
final HashMap<String, String> map = new HashMap<>();
map.put("name", randomNameGenerator("Tax_component_Name_", 5));
map.put("name", Utils.randomStringGenerator("Tax_component_Name_", 5));
map.put("dateFormat", "dd MMMM yyyy");
map.put("locale", "en");
map.put("percentage", percentage);
@@ -74,8 +77,8 @@ public final class TaxComponentHelper {
return map;
}
public static String randomNameGenerator(final String prefix, final int lenOfRandomSuffix) {
return Utils.randomStringGenerator(prefix, lenOfRandomSuffix);
public static PostTaxesComponentsResponse createTaxComponent(PostTaxesComponentsRequest request) {
return Calls.ok(FineractClientHelper.getFineractClient().taxComponents.createTaxComponent(request));
}
}
@@ -25,6 +25,9 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import org.apache.fineract.client.models.PostTaxesGroupRequest;
import org.apache.fineract.client.models.PostTaxesGroupResponse;
import org.apache.fineract.client.util.Calls;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -54,7 +57,7 @@ public final class TaxGroupHelper {
@Deprecated(forRemoval = true)
public static String getTaxGroupAsJSON(final Collection<Integer> taxComponentIds) {
final HashMap<String, Object> map = new HashMap<>();
map.put("name", randomNameGenerator("Tax_component_Name_", 5));
map.put("name", Utils.randomStringGenerator("Tax_group_Name_", 5));
map.put("dateFormat", "dd MMMM yyyy");
map.put("locale", "en");
map.put("taxComponents", getTaxGroupComponents(taxComponentIds));
@@ -84,8 +87,8 @@ public final class TaxGroupHelper {
return map;
}
public static String randomNameGenerator(final String prefix, final int lenOfRandomSuffix) {
return Utils.randomStringGenerator(prefix, lenOfRandomSuffix);
public static PostTaxesGroupResponse createTaxGroup(PostTaxesGroupRequest request) {
return Calls.ok(FineractClientHelper.getFineractClient().taxGroups.createTaxGroup(request));
}
}
@@ -65,10 +65,6 @@ public final class ChargesHelper {
public static final Integer SHARE_PURCHASE = 14;
public static final Integer SHARE_REDEEM = 15;
private static final Integer CHARGE_SAVINGS_NO_ACTIVITY_FEE = 16;
private static final Integer CHARGE_CLIENT_SPECIFIED_DUE_DATE = 1;
public static final Integer CHARGE_CALCULATION_TYPE_FLAT = 1;
public static final Integer CHARGE_CALCULATION_TYPE_PERCENTAGE_AMOUNT = 2;
public static final Integer CHARGE_CALCULATION_TYPE_PERCENTAGE_AMOUNT_AND_INTEREST = 3;