[OFBiz] SVN: r7548 - in trunk/applications/accounting: servicedef src/org/ofbiz/accounting/tax

jacopo@svn.ofbiz.org jacopo at svn.ofbiz.org
Tue May 9 08:30:29 CDT 2006


Author: jacopo
Date: 2006-05-09 08:30:19 -0500 (Tue, 09 May 2006)
New Revision: 7548

Modified:
   trunk/applications/accounting/servicedef/services_tax.xml
   trunk/applications/accounting/src/org/ofbiz/accounting/tax/TaxAuthorityServices.java
Log:
A few small, but significant, changes to the calcTax service.

1) Now the productStoreId is an optional parameter; if the productStoreId is passed, all the TaxAuthorityRateProduct records for that store and also the TARP records with an empty productStoreId are selected; if the productStoreId is not passed, only the TARP records with an empty productStoreId are selected.
2) A new (optional) parameter has been added: payToPartyId; if it is not passed, then the service works as now (i.e. it retrieves the payToPartyId from the ProductStore).

If none of the productStoreId and the payToPartyId parameters is passed, then an error is returned.


Modified: trunk/applications/accounting/servicedef/services_tax.xml
===================================================================
--- trunk/applications/accounting/servicedef/services_tax.xml	2006-05-09 04:08:52 UTC (rev 7547)
+++ trunk/applications/accounting/servicedef/services_tax.xml	2006-05-09 13:30:19 UTC (rev 7548)
@@ -30,7 +30,7 @@
     <!-- Tax Calc Interfaces -->
     <service name="calcTaxInterface" engine="interface" location="" invoke="">
         <description>Tax Calc Service Interface</description>
-        <attribute name="productStoreId" type="String" mode="IN" optional="false"><!-- this will be used to find the payToPartyId, if the payToPartyId parameter is not explicitly passed, and as one of the columns to constrain by on the lookup --></attribute>
+        <attribute name="productStoreId" type="String" mode="IN" optional="true"><!-- this will be used to find the payToPartyId, if the payToPartyId parameter is not explicitly passed, and as one of the columns to constrain by on the lookup --></attribute>
         <attribute name="payToPartyId" type="String" mode="IN" optional="true"/>
         <attribute name="billToPartyId" type="String" mode="IN" optional="true"><!-- would like to have this not-optional, but in some circumstances may need a tax estimate without knowing who the customer is --></attribute>
         <attribute name="itemProductList" type="java.util.List" mode="IN" optional="false"><!-- List of GenericValues --></attribute>

Modified: trunk/applications/accounting/src/org/ofbiz/accounting/tax/TaxAuthorityServices.java
===================================================================
--- trunk/applications/accounting/src/org/ofbiz/accounting/tax/TaxAuthorityServices.java	2006-05-09 04:08:52 UTC (rev 7547)
+++ trunk/applications/accounting/src/org/ofbiz/accounting/tax/TaxAuthorityServices.java	2006-05-09 13:30:19 UTC (rev 7548)
@@ -157,15 +157,17 @@
         GenericValue productStore = null;
         try {
             getTaxAuthorities(delegator, shippingAddress, taxAuthoritySet);
-            productStore = delegator.findByPrimaryKey("ProductStore", UtilMisc.toMap("productStoreId", productStoreId));
+            if (productStoreId != null) {
+                productStore = delegator.findByPrimaryKey("ProductStore", UtilMisc.toMap("productStoreId", productStoreId));
+            }
         } catch (GenericEntityException e) {
             String errMsg = "Data error getting tax settings: " + e.toString();
             Debug.logError(e, errMsg, module);
             return ServiceUtil.returnError(errMsg);
         }
         
-        if (productStore == null) {
-            throw new IllegalArgumentException("Could not find ProductStore with ID [" + productStoreId + "] for tax calculation");
+        if (productStore == null && payToPartyId == null) {
+            throw new IllegalArgumentException("Could not find payToPartyId [" + payToPartyId + "] or ProductStore [" + productStoreId + "] for tax calculation");
         }
         
         // Setup the return lists.
@@ -219,11 +221,21 @@
         List adjustments = FastList.newInstance();
 
         if (payToPartyId == null) {
-            payToPartyId = productStore.getString("payToPartyId");
+            if (productStore != null) {
+                payToPartyId = productStore.getString("payToPartyId");
+            }
         }
 
         // store expr
-        EntityCondition storeCond = new EntityExpr("productStoreId", EntityOperator.EQUALS, productStore.get("productStoreId"));
+        EntityCondition storeCond = null;
+        if (productStore != null) {
+            storeCond = new EntityExpr(
+                    new EntityExpr("productStoreId", EntityOperator.EQUALS, productStore.get("productStoreId")),
+                    EntityOperator.OR,
+                    new EntityExpr("productStoreId", EntityOperator.EQUALS, null));
+        } else {
+            storeCond = new EntityExpr("productStoreId", EntityOperator.EQUALS, null);
+        }
 
         // build the TaxAuthority expressions (taxAuthGeoId, taxAuthPartyId)
         List taxAuthCondOrList = FastList.newInstance();
@@ -314,7 +326,7 @@
                 String taxAuthGeoId = taxAuthorityRateProduct.getString("taxAuthGeoId");
                 String taxAuthPartyId = taxAuthorityRateProduct.getString("taxAuthPartyId");
 
-                // get glAccountId from TaxAuthorityGlAccount entity using the ProductStore.payToPartyId as the organizationPartyId
+                // get glAccountId from TaxAuthorityGlAccount entity using the payToPartyId as the organizationPartyId
                 GenericValue taxAuthorityGlAccount = delegator.findByPrimaryKey("TaxAuthorityGlAccount", UtilMisc.toMap("taxAuthPartyId", taxAuthPartyId, "taxAuthGeoId", taxAuthGeoId, "organizationPartyId", payToPartyId));
                 String taxAuthGlAccountId = null;
                 if (taxAuthorityGlAccount != null) {



More information about the Svn mailing list