svn commit: r567660 - in /ofbiz/trunk/applications: accounting/src/org/ofbiz/accounting/tax/TaxAuthorityServices.java order/src/org/ofbiz/order/shoppingcart/CheckOutHelper.java order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r567660 - in /ofbiz/trunk/applications: accounting/src/org/ofbiz/accounting/tax/TaxAuthorityServices.java order/src/org/ofbiz/order/shoppingcart/CheckOutHelper.java order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java

jonesde
Author: jonesde
Date: Mon Aug 20 04:55:22 2007
New Revision: 567660

URL: http://svn.apache.org/viewvc?rev=567660&view=rev
Log:
A bit of refactoring to isolate shipping address setting in the cart, plus some general debug statements now mostly commented out to track down how it's used

Modified:
    ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/tax/TaxAuthorityServices.java
    ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/CheckOutHelper.java
    ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java

Modified: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/tax/TaxAuthorityServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/tax/TaxAuthorityServices.java?rev=567660&r1=567659&r2=567660&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/tax/TaxAuthorityServices.java (original)
+++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/tax/TaxAuthorityServices.java Mon Aug 20 04:55:22 2007
@@ -211,16 +211,18 @@
             if (UtilValidate.isNotEmpty(postalCodeGeoId)) {
              geoIdSet.add(postalCodeGeoId);
             }
+        } else {
+            Debug.logWarning("shippingAddress was null, adding nothing to taxAuthoritySet", module);
         }
         
-        // Debug.logInfo("Tax calc geoIdSet before expand:" + geoIdSet, module);
+        //Debug.logInfo("Tax calc geoIdSet before expand:" + geoIdSet + "; this is for shippingAddress=" + shippingAddress, module);
         // 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);
-        // Debug.logInfo("Tax calc geoIdSet after expand:" + geoIdSet, module);
+        //Debug.logInfo("Tax calc geoIdSet after expand:" + geoIdSet, module);
 
         List taxAuthorityRawList = delegator.findByConditionCache("TaxAuthority", new EntityExpr("taxAuthGeoId", EntityOperator.IN, geoIdSet), null, null);
         taxAuthoritySet.addAll(taxAuthorityRawList);
-        // Debug.logInfo("Tax calc taxAuthoritySet after expand:" + taxAuthoritySet, module);
+        //Debug.logInfo("Tax calc taxAuthoritySet after expand:" + taxAuthoritySet, module);
     }
 
     private static List getTaxAdjustments(GenericDelegator delegator, GenericValue product, GenericValue productStore, String payToPartyId, String billToPartyId, Set taxAuthoritySet, BigDecimal itemPrice, BigDecimal itemAmount, BigDecimal shippingAmount) {
@@ -355,7 +357,7 @@
                 if (taxAuthGeoId != null) adjValue.set("taxAuthGeoId", taxAuthGeoId);
 
                 // check to see if this party has a tax ID for this, and if the party is tax exempt in the primary (most-local) jurisdiction
-                if (UtilValidate.isNotEmpty(billToPartyId) && taxAuthGeoId != null) {
+                if (UtilValidate.isNotEmpty(billToPartyId) && UtilValidate.isNotEmpty(taxAuthGeoId)) {
                     // see if partyId is a member of any groups, if so honor their tax exemptions
                     // look for PartyRelationship with partyRelationshipTypeId=GROUP_ROLLUP, the partyIdTo is the group member, so the partyIdFrom is the groupPartyId
                     Set billToPartyIdSet = FastSet.newInstance();

Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/CheckOutHelper.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/CheckOutHelper.java?rev=567660&r1=567659&r2=567660&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/CheckOutHelper.java (original)
+++ ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/CheckOutHelper.java Mon Aug 20 04:55:22 2007
@@ -730,7 +730,7 @@
     }
 
     public void calcAndAddTax(GenericValue shipAddress) throws GeneralException {
-        if (!"SALES_ORDER".equals(cart.getOrderType()) || (UtilValidate.isEmpty(cart.getShippingContactMechId()) && cart.getBillingAddress()==null)) {
+        if (!"SALES_ORDER".equals(cart.getOrderType()) || (UtilValidate.isEmpty(cart.getShippingContactMechId()) && cart.getBillingAddress() == null && shipAddress == null)) {
             return;
         }
 
@@ -772,6 +772,8 @@
         List price = new ArrayList(totalItems);
         List shipAmt = new ArrayList(totalItems);
 
+        // Debug.logInfo("====== makeTaxContext passed in shipAddress=" + shipAddress, module);
+        
         for (int i = 0; i < totalItems; i++) {
             ShoppingCartItem cartItem = (ShoppingCartItem) csi.shipItemInfo.get(i);
             ShoppingCart.CartShipInfo.CartShipItemInfo itemInfo = csi.getShipItemInfo(cartItem);
@@ -788,6 +790,7 @@
         BigDecimal shipAmount = new BigDecimal(csi.shipEstimate);
         if (shipAddress == null) {
             shipAddress = cart.getShippingAddress(shipGroup);
+            // Debug.logInfo("====== makeTaxContext set shipAddress to cart.getShippingAddress(shipGroup): " + shipAddress, module);
         }
 
         // no shipping address; try the billing address
@@ -797,7 +800,7 @@
                 GenericValue billAddr = cpi.getBillingAddress(delegator);
                 if (billAddr != null) {
                     shipAddress = billAddr;
-                    Debug.logInfo("Found address from payment method.", module);
+                    Debug.logInfo("In makeTaxContext no shipping address, but found address with ID [" + shipAddress.get("contactMechId") + "] from payment method.", module);
                 }
                 break;
             }

Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java?rev=567660&r1=567659&r2=567660&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java (original)
+++ ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java Mon Aug 20 04:55:22 2007
@@ -1898,7 +1898,7 @@
     }
 
     public CartShipInfo getShipInfo(int idx) {
-        if (idx == -1 ) {
+        if (idx == -1) {
             return null;
         }
 
@@ -2108,7 +2108,7 @@
                 }
             }
         }
-        csi.contactMechId = shippingContactMechId;
+        csi.setContactMechId(shippingContactMechId);
     }
 
     public void setShippingContactMechId(String shippingContactMechId) {
@@ -2118,7 +2118,7 @@
     /** Returns the shipping contact mech id. */
     public String getShippingContactMechId(int idx) {
         CartShipInfo csi = this.getShipInfo(idx);
-        return csi.contactMechId;
+        return csi.getContactMechId();
     }
 
     public String getShippingContactMechId() {
@@ -4054,7 +4054,7 @@
         public LinkedMap shipItemInfo = new LinkedMap();
         public List shipTaxAdj = new LinkedList();
         public String orderTypeId = null;
-        public String contactMechId = null;
+        private String internalContactMechId = null;
         public String shipmentMethodTypeId = null;
         public String supplierPartyId = null;
         public String carrierRoleTypeId = null;
@@ -4068,7 +4068,11 @@
         public Timestamp shipAfterDate = null;
 
         public String getOrderTypeId() { return orderTypeId; }
-        public String getContactMechId() { return contactMechId; }
+        public String getContactMechId() { return internalContactMechId; }
+        public void setContactMechId(String contactMechId) {
+            this.internalContactMechId = contactMechId;
+            // Debug.logInfo(new Exception(), "Set CartShipInfo.contactMechId=" + this.internalContactMechId, module);
+        }
         public String getCarrierPartyId() { return carrierPartyId; }
         public String getSupplierPartyId() { return supplierPartyId; }
         public String getShipmentMethodTypeId() { return shipmentMethodTypeId; }
@@ -4078,10 +4082,10 @@
             List values = new LinkedList();
             
             // create order contact mech for shipping address
-            if (contactMechId != null) {
+            if (this.internalContactMechId != null) {
                 GenericValue orderCm = delegator.makeValue("OrderContactMech", null);
                 orderCm.set("contactMechPurposeTypeId", "SHIPPING_LOCATION");
-                orderCm.set("contactMechId", contactMechId);
+                orderCm.set("contactMechId", this.internalContactMechId);
                 values.add(orderCm);
             }
 
@@ -4093,7 +4097,7 @@
             shipGroup.set("supplierPartyId", supplierPartyId);
             shipGroup.set("shippingInstructions", shippingInstructions);
             shipGroup.set("giftMessage", giftMessage);
-            shipGroup.set("contactMechId", contactMechId);
+            shipGroup.set("contactMechId", this.internalContactMechId);
             shipGroup.set("maySplit", maySplit);
             shipGroup.set("isGift", isGift);
             shipGroup.set("shipGroupSeqId", shipGroupSeqId);
@@ -4219,9 +4223,9 @@
                 // the products already in the cart
                 GenericValue shippingAddress = null;
                 try {
-                    shippingAddress = item.getDelegator().findByPrimaryKey("PostalAddress", UtilMisc.toMap("contactMechId", contactMechId));
+                    shippingAddress = item.getDelegator().findByPrimaryKey("PostalAddress", UtilMisc.toMap("contactMechId", this.internalContactMechId));
                 } catch(GenericEntityException gee) {
-                    Debug.logError(gee, "Error retrieving the shipping address for contactMechId [" + contactMechId + "].", module);
+                    Debug.logError(gee, "Error retrieving the shipping address for contactMechId [" + this.internalContactMechId + "].", module);
                 }
                 if (shippingAddress != null) {
                     GenericValue product = item.getProduct();