FINERACT-2425: Tax component and Tax Group refactoring

This commit is contained in:
Jose Alberto Hernandez
2026-01-03 01:56:47 +01:00
committed by Adam Saghy
parent cbf8a4f5ab
commit b7306f19d0
33 changed files with 525 additions and 295 deletions
@@ -0,0 +1,117 @@
/**
* 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.integrationtests;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.fineract.client.models.GetTaxesComponentsResponse;
import org.apache.fineract.client.models.GetTaxesGroupResponse;
import org.apache.fineract.client.models.GetTaxesGroupTaxAssociations;
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.accounting.Account;
import org.apache.fineract.integrationtests.common.accounting.AccountHelper;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class TaxesTest {
@Test
public void createTaxComponentTest() {
Long taxComponentId = createTaxComponentWithLiabilityToCredit("taxComponent");
GetTaxesComponentsResponse taxComponentDetails = TaxComponentHelper.retrieveTaxComponent(taxComponentId);
Assertions.assertNotNull(taxComponentDetails);
Assertions.assertNotNull(taxComponentDetails.getId());
Assertions.assertEquals(taxComponentId, taxComponentDetails.getId());
taxComponentId = createTaxComponentWithLiabilityToDebit("taxComponent");
taxComponentDetails = TaxComponentHelper.retrieveTaxComponent(taxComponentId);
Assertions.assertNotNull(taxComponentDetails);
Assertions.assertNotNull(taxComponentDetails.getId());
Assertions.assertEquals(taxComponentId, taxComponentDetails.getId());
}
@Test
public void createTaxGroupTest() {
List<GetTaxesGroupResponse> allTaxGroups = TaxGroupHelper.retrieveAllTaxGroups();
Assertions.assertNotNull(allTaxGroups);
final Long taxComponentId = createTaxComponentWithLiabilityToCredit("taxComponent");
final Set<PostTaxesGroupTaxComponents> taxComponentsSet = new HashSet<>();
taxComponentsSet.add(new PostTaxesGroupTaxComponents().taxComponentId(taxComponentId).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);
Assertions.assertNotNull(taxGroupResponse.getResourceId());
final GetTaxesGroupResponse taxGroupDetails = TaxGroupHelper.retrieveTaxGroup(taxGroupResponse.getResourceId());
Assertions.assertNotNull(taxGroupDetails);
Assertions.assertEquals(taxGroupResponse.getResourceId(), taxGroupDetails.getId());
Assertions.assertFalse(taxGroupDetails.getTaxAssociations().isEmpty());
GetTaxesGroupTaxAssociations taxAssociation = taxGroupDetails.getTaxAssociations().iterator().next();
Assertions.assertNotNull(taxAssociation);
Assertions.assertEquals(taxComponentId, taxAssociation.getTaxComponent().getId());
allTaxGroups = TaxGroupHelper.retrieveAllTaxGroups();
Assertions.assertNotNull(allTaxGroups);
Assertions.assertTrue(allTaxGroups.size() > 0);
}
private Long createTaxComponentWithLiabilityToCredit(final String taxComponentPrefix) {
final Account taxComponentGlAccount = AccountHelper.createLiabilityGlAccount(taxComponentPrefix);
final PostTaxesComponentsRequest taxComponentRequest = new PostTaxesComponentsRequest()
.name(Utils.randomStringGenerator(taxComponentPrefix, 4)).percentage(12.0f).startDate("01 January 2023")
.creditAccountType(Integer.valueOf(taxComponentGlAccount.getAccountType().toString()))
.creditAccountId(taxComponentGlAccount.getAccountID().longValue()).dateFormat(Utils.DATE_FORMAT).locale(Utils.LOCALE);
final PostTaxesComponentsResponse taxComponentRespose = TaxComponentHelper.createTaxComponent(taxComponentRequest);
Assertions.assertNotNull(taxComponentRespose);
Assertions.assertNotNull(taxComponentRespose.getResourceId());
return taxComponentRespose.getResourceId();
}
private Long createTaxComponentWithLiabilityToDebit(final String taxComponentPrefix) {
final Account taxComponentGlAccount = AccountHelper.createLiabilityGlAccount(taxComponentPrefix);
final PostTaxesComponentsRequest taxComponentRequest = new PostTaxesComponentsRequest()
.name(Utils.randomStringGenerator(taxComponentPrefix, 4)).percentage(12.0f).startDate("01 January 2023")
.debitAccountType(Integer.valueOf(taxComponentGlAccount.getAccountType().toString()))
.debitAccountId(taxComponentGlAccount.getAccountID().longValue()).dateFormat(Utils.DATE_FORMAT).locale(Utils.LOCALE);
final PostTaxesComponentsResponse taxComponentRespose = TaxComponentHelper.createTaxComponent(taxComponentRequest);
Assertions.assertNotNull(taxComponentRespose);
Assertions.assertNotNull(taxComponentRespose.getResourceId());
return taxComponentRespose.getResourceId();
}
}
@@ -22,6 +22,7 @@ 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.GetTaxesComponentsResponse;
import org.apache.fineract.client.models.PostTaxesComponentsRequest;
import org.apache.fineract.client.models.PostTaxesComponentsResponse;
import org.apache.fineract.client.util.Calls;
@@ -57,7 +58,7 @@ public final class TaxComponentHelper {
final HashMap<String, String> map = getBasicTaxComponentMap(percentage);
if (creditAccountId != null) {
map.put("creditAccountType", Account.AccountType.LIABILITY.toString());
map.put("creditAcountId", String.valueOf(creditAccountId));
map.put("creditAccountId", String.valueOf(creditAccountId));
}
LOG.info("map : {}", map);
return new Gson().toJson(map);
@@ -81,4 +82,8 @@ public final class TaxComponentHelper {
return Calls.ok(FineractClientHelper.getFineractClient().taxComponents.createTaxComponent(request));
}
public static GetTaxesComponentsResponse retrieveTaxComponent(Long taxComponentId) {
return Calls.ok(FineractClientHelper.getFineractClient().taxComponents.retrieveTaxComponent(taxComponentId));
}
}
@@ -25,6 +25,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import org.apache.fineract.client.models.GetTaxesGroupResponse;
import org.apache.fineract.client.models.PostTaxesGroupRequest;
import org.apache.fineract.client.models.PostTaxesGroupResponse;
import org.apache.fineract.client.util.Calls;
@@ -91,4 +92,12 @@ public final class TaxGroupHelper {
return Calls.ok(FineractClientHelper.getFineractClient().taxGroups.createTaxGroup(request));
}
public static GetTaxesGroupResponse retrieveTaxGroup(Long taxGroupId) {
return Calls.ok(FineractClientHelper.getFineractClient().taxGroups.retrieveTaxGroup(taxGroupId));
}
public static List<GetTaxesGroupResponse> retrieveAllTaxGroups() {
return Calls.ok(FineractClientHelper.getFineractClient().taxGroups.retrieveAllTaxGroups());
}
}
@@ -88,6 +88,7 @@ public final class Utils {
public static final String TENANT_TIME_ZONE = "Asia/Kolkata";
public static final String DATE_FORMAT = "dd MMMM yyyy";
public static final String DATE_TIME_FORMAT = "dd MMMM yyyy HH:mm";
public static final String LOCALE = "en";
public static final DateTimeFormatter dateFormatter = new DateTimeFormatterBuilder().appendPattern(DATE_FORMAT).toFormatter();
public static final DateTimeFormatter dateTimeFormatter = new DateTimeFormatterBuilder().appendPattern(DATE_TIME_FORMAT).toFormatter();
private static final Logger LOG = LoggerFactory.getLogger(Utils.class);
@@ -21,7 +21,9 @@ package org.apache.fineract.integrationtests.common.accounting;
import io.restassured.specification.RequestSpecification;
import io.restassured.specification.ResponseSpecification;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import org.apache.fineract.accounting.glaccount.domain.GLAccountType;
import org.apache.fineract.client.models.DeleteGLAccountsResponse;
import org.apache.fineract.client.models.GetGLAccountsResponse;
import org.apache.fineract.client.models.PostGLAccountsRequest;
@@ -31,6 +33,7 @@ import org.apache.fineract.client.models.PutGLAccountsResponse;
import org.apache.fineract.client.util.Calls;
import org.apache.fineract.integrationtests.common.FineractClientHelper;
import org.apache.fineract.integrationtests.common.Utils;
import org.junit.jupiter.api.Assertions;
@SuppressWarnings("rawtypes")
public class AccountHelper {
@@ -161,4 +164,49 @@ public class AccountHelper {
public static GetGLAccountsResponse getGLAccount(final Long glAccountId) {
return Calls.ok(FineractClientHelper.getFineractClient().glAccounts.retreiveAccount(glAccountId, false));
}
public static Account createAssetGlAccount(final String glAccountName) {
PostGLAccountsResponse postGLAccountsResponse = createGLAccount(
createGlAccount(GLAccountType.ASSET, Utils.uniqueRandomStringGenerator(glAccountName, 6), null));
Assertions.assertNotNull(postGLAccountsResponse);
return new Account(postGLAccountsResponse.getResourceId().intValue(), Account.AccountType.ASSET);
}
public static Account createLiabilityGlAccount(final String glAccountName) {
PostGLAccountsResponse postGLAccountsResponse = createGLAccount(
createGlAccount(GLAccountType.LIABILITY, Utils.uniqueRandomStringGenerator(glAccountName, 6), null));
Assertions.assertNotNull(postGLAccountsResponse);
return new Account(postGLAccountsResponse.getResourceId().intValue(), Account.AccountType.LIABILITY);
}
public static Account createIncomeGlAccount(final String glAccountName) {
PostGLAccountsResponse postGLAccountsResponse = createGLAccount(
createGlAccount(GLAccountType.INCOME, Utils.uniqueRandomStringGenerator(glAccountName, 6), null));
Assertions.assertNotNull(postGLAccountsResponse);
return new Account(postGLAccountsResponse.getResourceId().intValue(), Account.AccountType.INCOME);
}
public static Account createExpenseGlAccount(final String glAccountName) {
PostGLAccountsResponse postGLAccountsResponse = createGLAccount(
createGlAccount(GLAccountType.EXPENSE, Utils.uniqueRandomStringGenerator(glAccountName, 6), null));
Assertions.assertNotNull(postGLAccountsResponse);
return new Account(postGLAccountsResponse.getResourceId().intValue(), Account.AccountType.EXPENSE);
}
public static Account createEquityGlAccount(final String glAccountName) {
PostGLAccountsResponse postGLAccountsResponse = createGLAccount(
createGlAccount(GLAccountType.EQUITY, Utils.uniqueRandomStringGenerator(glAccountName, 6), null));
Assertions.assertNotNull(postGLAccountsResponse);
return new Account(postGLAccountsResponse.getResourceId().intValue(), Account.AccountType.EQUITY);
}
public static PostGLAccountsRequest createGlAccount(final GLAccountType glAccountType, final String glAccountName,
final Long parentAccountId) {
return new PostGLAccountsRequest().type(glAccountType.getValue()).glCode(createGlCode(glAccountType)).manualEntriesAllowed(true)
.usage(1).parentId(parentAccountId).description(glAccountName).name(glAccountName);
}
public static String createGlCode(final GLAccountType glAccountType) {
return Utils.uniqueRandomStringGenerator(glAccountType.getValue().toString() + Calendar.getInstance().getTimeInMillis(), 2);
}
}