[OFBiz] SVN: r7536 - trunk/applications/accounting/src/org/ofbiz/accounting/tax
jacopo@svn.ofbiz.org
jacopo at svn.ofbiz.org
Sat May 6 11:02:44 CDT 2006
Author: jacopo
Date: 2006-05-06 11:02:38 -0500 (Sat, 06 May 2006)
New Revision: 7536
Modified:
trunk/applications/accounting/src/org/ofbiz/accounting/tax/TaxAuthorityServices.java
Log:
This patch doesn't contain functional changes:
I've moved the code that retrieves the tax authorities from the rateProductTaxCalc service into a new method (this will be useful to share the same logic among the rateProductTaxCalc and the rateProductTaxCalcForDisplay methods.
There is also a bug fix for NPE if shippingAmount is null.
Modified: trunk/applications/accounting/src/org/ofbiz/accounting/tax/TaxAuthorityServices.java
===================================================================
--- trunk/applications/accounting/src/org/ofbiz/accounting/tax/TaxAuthorityServices.java 2006-05-06 13:54:44 UTC (rev 7535)
+++ trunk/applications/accounting/src/org/ofbiz/accounting/tax/TaxAuthorityServices.java 2006-05-06 16:02:38 UTC (rev 7536)
@@ -136,7 +136,7 @@
result.put("priceWithTax", priceWithTax);
return result;
}
-
+
public static Map rateProductTaxCalc(DispatchContext dctx, Map context) {
GenericDelegator delegator = dctx.getDelegator();
String productStoreId = (String) context.get("productStoreId");
@@ -148,30 +148,14 @@
BigDecimal orderShippingAmount = (BigDecimal) context.get("orderShippingAmount");
GenericValue shippingAddress = (GenericValue) context.get("shippingAddress");
+ if (shippingAddress == null || (shippingAddress.get("countryGeoId") == null && shippingAddress.get("stateProvinceGeoId") == null)) {
+ return ServiceUtil.returnError("The address(es) used for tax calculation did not have State/Province or Country values set, so we cannot determine the taxes to charge.");
+ }
// without knowing the TaxAuthority parties, just find all TaxAuthories for the set of IDs...
Set taxAuthoritySet = FastSet.newInstance();
GenericValue productStore = null;
try {
- Set geoIdSet = FastSet.newInstance();
- if (shippingAddress != null) {
- if (shippingAddress.getString("countryGeoId") != null) {
- geoIdSet.add(shippingAddress.getString("countryGeoId"));
- }
- if (shippingAddress.getString("stateProvinceGeoId") != null) {
- geoIdSet.add(shippingAddress.getString("stateProvinceGeoId"));
- }
- }
-
- if (geoIdSet.size() == 0) {
- return ServiceUtil.returnError("The address(es) used for tax calculation did not have State/Province or Country values set, so we cannot determine the taxes to charge.");
- }
-
- // get the most granular, or all available, geoIds and then find parents by GeoAssoc with geoAssocTypeId="REGIONS" and geoIdTo=<granular geoId> and find the GeoAssoc.geoId
- geoIdSet = GeoWorker.expandGeoRegionDeep(geoIdSet, delegator);
-
- List taxAuthorityRawList = delegator.findByConditionCache("TaxAuthority", new EntityExpr("taxAuthGeoId", EntityOperator.IN, geoIdSet), null, null);
- taxAuthoritySet.addAll(taxAuthorityRawList);
-
+ getTaxAuthorities(delegator, shippingAddress, taxAuthoritySet);
productStore = delegator.findByPrimaryKey("ProductStore", UtilMisc.toMap("productStoreId", productStoreId));
} catch (GenericEntityException e) {
String errMsg = "Data error getting tax settings: " + e.toString();
@@ -212,6 +196,23 @@
return result;
}
+ private static void getTaxAuthorities(GenericDelegator delegator, GenericValue shippingAddress, Set taxAuthoritySet) throws GenericEntityException {
+ Set geoIdSet = FastSet.newInstance();
+ if (shippingAddress != null) {
+ if (shippingAddress.getString("countryGeoId") != null) {
+ geoIdSet.add(shippingAddress.getString("countryGeoId"));
+ }
+ if (shippingAddress.getString("stateProvinceGeoId") != null) {
+ geoIdSet.add(shippingAddress.getString("stateProvinceGeoId"));
+ }
+ }
+ // get the most granular, or all available, geoIds and then find parents by GeoAssoc with geoAssocTypeId="REGIONS" and geoIdTo=<granular geoId> and find the GeoAssoc.geoId
+ geoIdSet = GeoWorker.expandGeoRegionDeep(geoIdSet, delegator);
+
+ List taxAuthorityRawList = delegator.findByConditionCache("TaxAuthority", new EntityExpr("taxAuthGeoId", EntityOperator.IN, geoIdSet), null, null);
+ taxAuthoritySet.addAll(taxAuthorityRawList);
+ }
+
private static List getTaxAdjustments(GenericDelegator delegator, GenericValue product, GenericValue productStore, String billToPartyId, Set taxAuthoritySet, BigDecimal itemPrice, BigDecimal itemAmount, BigDecimal shippingAmount) {
Timestamp nowTimestamp = UtilDateTime.nowTimestamp();
List adjustments = FastList.newInstance();
@@ -295,7 +296,7 @@
if (product != null && (product.get("taxable") == null || (product.get("taxable") != null && product.getBoolean("taxable").booleanValue()))) {
taxable = taxable.add(itemAmount);
}
- if (taxAuthorityRateProduct != null && (taxAuthorityRateProduct.get("taxShipping") == null || (taxAuthorityRateProduct.get("taxShipping") != null && taxAuthorityRateProduct.getBoolean("taxShipping").booleanValue()))) {
+ if (shippingAmount != null && taxAuthorityRateProduct != null && (taxAuthorityRateProduct.get("taxShipping") == null || (taxAuthorityRateProduct.get("taxShipping") != null && taxAuthorityRateProduct.getBoolean("taxShipping").booleanValue()))) {
taxable = taxable.add(shippingAmount);
}
More information about the Svn
mailing list