svn commit: r882454 - in /ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart: ShoppingCart.java ShoppingCartEvents.java

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

svn commit: r882454 - in /ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart: ShoppingCart.java ShoppingCartEvents.java

ashish-18
Author: ashish
Date: Fri Nov 20 08:59:05 2009
New Revision: 882454

URL: http://svn.apache.org/viewvc?rev=882454&view=rev
Log:
Applied patch from jira issue OFBIZ-3208 - On order view page when clicking on "Create As New Order", the adjustments Shipping and Handling and Sales Tax are duplicated.

Patch will resolve the following Issues

1) Shipping and Handling Charges are added twice in new order amount.
2) Sales Tax are added twice in new order amount.
3) Add extra tax on shipping and handling charges for new order.
4) When click on "Create as New Order" Link, it is Giving NPE on some Promotion (Happy Hour
Promotion 9020).
5) Click on "Edit Items" Link and then "Update" Link it is it is Giving NPE on some Promotion (Happy
Hour Promotion 9020).

Thanks Arpit for the contribution.

Modified:
    ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java
    ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java

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=882454&r1=882453&r2=882454&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 Fri Nov 20 08:59:05 2009
@@ -829,6 +829,7 @@
             return null;
         }
         return (ShoppingCartItem) cartLines.get(index);
+        
     }
 
     public ShoppingCartItem findCartItem(String orderItemSeqId) {
@@ -2010,7 +2011,10 @@
     }
 
     public void setItemShipGroupQty(int itemIndex, BigDecimal quantity, int idx) {
-        this.setItemShipGroupQty(this.findCartItem(itemIndex), itemIndex, quantity, idx);
+        ShoppingCartItem itemIdx = this.findCartItem(itemIndex);
+        if(itemIdx != null) {
+            this.setItemShipGroupQty(itemIdx, itemIndex, quantity, idx);
+        }
     }
 
     public void setItemShipGroupQty(ShoppingCartItem item, BigDecimal quantity, int idx) {
@@ -2027,16 +2031,19 @@
             }
 
             // never set more than quantity ordered
-            if (quantity.compareTo(item.getQuantity()) > 0) {
-                quantity = item.getQuantity();
-            }
-
-            // re-set the ship group's before and after dates based on the item's
-            csi.resetShipBeforeDateIfAfter(item.getShipBeforeDate());
-            csi.resetShipAfterDateIfBefore(item.getShipAfterDate());
-
-            CartShipInfo.CartShipItemInfo csii = csi.setItemInfo(item, quantity);
-            this.checkShipItemInfo(csi, csii);
+            if (item != null) {
+                if (quantity.compareTo(item.getQuantity()) > 0) {
+                    quantity = item.getQuantity();
+                }
+            
+
+                // re-set the ship group's before and after dates based on the item's
+                csi.resetShipBeforeDateIfAfter(item.getShipBeforeDate());
+                csi.resetShipAfterDateIfBefore(item.getShipAfterDate());
+    
+                CartShipInfo.CartShipItemInfo csii = csi.setItemInfo(item, quantity);
+                this.checkShipItemInfo(csi, csii);
+            }
         }
     }
 

Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java?rev=882454&r1=882453&r2=882454&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java (original)
+++ ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java Fri Nov 20 08:59:05 2009
@@ -20,20 +20,21 @@
 
 import java.math.BigDecimal;
 import java.math.MathContext;
+import java.sql.Timestamp;
 import java.text.NumberFormat;
+import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
-import javolution.util.FastMap;
-import java.sql.Timestamp;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpSession;
 
 import javolution.util.FastList;
+import javolution.util.FastMap;
 
 import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.util.UtilDateTime;
@@ -1307,6 +1308,7 @@
         LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
         HttpSession session = request.getSession();
         GenericValue userLogin = (GenericValue)session.getAttribute("userLogin");
+        Delegator delegator = (Delegator) request.getAttribute("delegator");
 
         String orderId = request.getParameter("orderId");
 
@@ -1322,7 +1324,49 @@
              }
 
             cart = (ShoppingCart) outMap.get("shoppingCart");
-            
+
+            cart.removeAdjustmentByType("SALES_TAX");
+            cart.removeAdjustmentByType("PROMOTION_ADJUSTMENT");
+            String shipGroupSeqId = null;
+            long groupIndex = cart.getShipInfoSize();
+            List orderAdjustmentList = new ArrayList();
+            List orderAdjustments = new ArrayList();
+            orderAdjustments = cart.getAdjustments();
+            try {
+                orderAdjustmentList = delegator.findList("OrderAdjustment", EntityCondition.makeCondition("orderId", EntityOperator.EQUALS, orderId), null, null, null, false);
+            } catch (Exception e) {
+                Debug.logError(e, module);
+            }
+            for (long itr = 1; itr <= groupIndex; itr++) {
+                shipGroupSeqId = UtilFormatOut.formatPaddedNumber(1, 5);
+                List<GenericValue> duplicateAdjustmentList = new ArrayList<GenericValue>();
+                for (GenericValue adjustment: (List<GenericValue>)orderAdjustmentList) {
+                    if ("PROMOTION_ADJUSTMENT".equals(adjustment.get("orderAdjustmentTypeId"))) {
+                        cart.addAdjustment(adjustment);
+                    }
+                    if ("SALES_TAX".equals(adjustment.get("orderAdjustmentTypeId"))) {
+                        if (adjustment.get("description") != null
+                                    && ((String)adjustment.get("description")).startsWith("Tax adjustment due")) {
+                                cart.addAdjustment(adjustment);
+                            }
+                        if ( adjustment.get("comments") != null
+                                && ((String)adjustment.get("comments")).startsWith("Added manually by")) {
+                            cart.addAdjustment(adjustment);
+                        }
+                    }
+                }
+                for (GenericValue orderAdjustment: (List<GenericValue>)orderAdjustments) {
+                    if ("OrderAdjustment".equals(orderAdjustment.getEntityName())) {
+                        if (("SHIPPING_CHARGES".equals(orderAdjustment.get("orderAdjustmentTypeId"))) &&
+                                orderAdjustment.get("orderId").equals(orderId) &&
+                                orderAdjustment.get("shipGroupSeqId").equals(shipGroupSeqId) && orderAdjustment.get("comments") == null) {
+                            // Removing objects from list for old Shipping and Handling Charges Adjustment and Sales Tax Adjustment.
+                            duplicateAdjustmentList.add(orderAdjustment);
+                        }
+                    }
+                }
+                orderAdjustments.removeAll(duplicateAdjustmentList);
+            }
         } catch (GenericServiceException exc) {
             request.setAttribute("_ERROR_MESSAGE_", exc.getMessage());
             return "error";