You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jo...@apache.org on 2011/02/11 04:56:51 UTC

svn commit: r1069671 - in /ofbiz/trunk/applications/order/src/org/ofbiz/order: order/OrderReadHelper.java shoppingcart/ShoppingCartServices.java

Author: jonesde
Date: Fri Feb 11 03:56:50 2011
New Revision: 1069671

URL: http://svn.apache.org/viewvc?rev=1069671&view=rev
Log:
Fixed issue with orders that have some items cancelled and others that are not after the cancelled items; when loading the order into the cart for changes the ship group stuff was getting off by one because it wasn't checking for the item status, and was doing redundant calls to set quantities that also sometimes failed; also changed a couple of places to treat the VAT_* types like the SALES_TAX adjustment type

Modified:
    ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java
    ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartServices.java

Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java?rev=1069671&r1=1069670&r2=1069671&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java (original)
+++ ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java Fri Feb 11 03:56:50 2011
@@ -2701,7 +2701,9 @@ public class OrderReadHelper {
 
                 boolean includeAdjustment = false;
 
-                if ("SALES_TAX".equals(orderAdjustment.getString("orderAdjustmentTypeId"))) {
+                if ("SALES_TAX".equals(orderAdjustment.getString("orderAdjustmentTypeId")) ||
+                        "VAT_TAX".equals(orderAdjustment.getString("orderAdjustmentTypeId")) ||
+                        "VAT_PRICE_CORRECT".equals(orderAdjustment.getString("orderAdjustmentTypeId"))) {
                     if (includeTax) includeAdjustment = true;
                 } else if ("SHIPPING_CHARGES".equals(orderAdjustment.getString("orderAdjustmentTypeId"))) {
                     if (includeShipping) includeAdjustment = true;

Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartServices.java?rev=1069671&r1=1069670&r2=1069671&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartServices.java (original)
+++ ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartServices.java Fri Feb 11 03:56:50 2011
@@ -539,6 +539,7 @@ public class ShoppingCartServices {
                 // set the PO number on the cart
                 cart.setPoNumber(item.getString("correspondingPoId"));
 
+                // get all item adjustments EXCEPT tax adjustments
                 List<GenericValue> itemAdjustments = orh.getOrderItemAdjustments(item);
                 if (itemAdjustments != null) {
                     for(GenericValue itemAdjustment : itemAdjustments) {
@@ -556,6 +557,9 @@ public class ShoppingCartServices {
             if (UtilValidate.isNotEmpty(orderItems)) {
                 int itemIndex = 0;
                 for (GenericValue item : orderItems) {
+                    // if rejected or cancelled ignore, just like above otherwise all indexes will be off by one!
+                    if ("ITEM_REJECTED".equals(item.getString("statusId")) || "ITEM_CANCELLED".equals(item.getString("statusId"))) continue;
+
                     List<GenericValue> orderItemAdjustments = orh.getOrderItemAdjustments(item);
                     // set the item's ship group info
                     List<GenericValue> shipGroupAssocs = orh.getOrderItemShipGroupAssocs(item);
@@ -568,17 +572,32 @@ public class ShoppingCartServices {
 
                         String cartShipGroupIndexStr = sgAssoc.getString("shipGroupSeqId");
                         int cartShipGroupIndex = NumberUtils.toInt(cartShipGroupIndexStr);
-
                         cartShipGroupIndex = cartShipGroupIndex - 1;
+
                         if (cartShipGroupIndex > 0) {
                             cart.positionItemToGroup(itemIndex, shipGroupQty, 0, cartShipGroupIndex, false);
                         }
 
-                        cart.setItemShipGroupQty(itemIndex, shipGroupQty, cartShipGroupIndex);
-
-                        List<GenericValue> shipGroupItemAdjustments = EntityUtil.filterByAnd(orderItemAdjustments, UtilMisc.toMap("shipGroupSeqId", cartShipGroupIndexStr));
+                        // because the ship groups are setup before loading items, and the ShoppingCart.addItemToEnd
+                        // method is called when loading items above and it calls ShoppingCart.setItemShipGroupQty,
+                        // this may not be necessary here, so check it first as calling it here with 0 quantity and
+                        // such ends up removing cart items from the group, which causes problems later with inventory
+                        // reservation, tax calculation, etc.
                         ShoppingCart.CartShipInfo csi = cart.getShipInfo(cartShipGroupIndex);
                         ShoppingCartItem cartItem = cart.findCartItem(itemIndex);
+                        if (cartItem == null || cartItem.getQuantity() == null ||
+                                BigDecimal.ZERO.equals(cartItem.getQuantity()) ||
+                                shipGroupQty.equals(cartItem.getQuantity())) {
+                            Debug.logInfo("In loadCartFromOrder not adding item [" + item.getString("orderItemSeqId") +
+                                    "] to ship group with index [" + itemIndex + "]; group quantity is [" + shipGroupQty +
+                                    "] item quantity is [" + (cartItem != null ? cartItem.getQuantity() : "no cart item") +
+                                    "] cartShipGroupIndex is [" + cartShipGroupIndex + "], csi.shipItemInfo.size(): " +
+                                    csi.shipItemInfo.size(), module);
+                        } else {
+                            cart.setItemShipGroupQty(itemIndex, shipGroupQty, cartShipGroupIndex);
+                        }
+
+                        List<GenericValue> shipGroupItemAdjustments = EntityUtil.filterByAnd(orderItemAdjustments, UtilMisc.toMap("shipGroupSeqId", cartShipGroupIndexStr));
                         if (cartItem == null) {
                             Debug.logWarning("In loadCartFromOrder could not find cart item for itemIndex=" + itemIndex + ", for orderId=" + orderId, module);
                         } else {
@@ -587,8 +606,10 @@ public class ShoppingCartServices {
                                 Debug.logWarning("In loadCartFromOrder could not find CartShipItemInfo for itemIndex=" + itemIndex + ", for orderId=" + orderId, module);
                             } else {
                                 List<GenericValue> itemTaxAdj = cartShipItemInfo.itemTaxAdj;
-                                for(GenericValue shipGroupItemAdjustment : shipGroupItemAdjustments) {
-                                    if ("SALES_TAX".equals(shipGroupItemAdjustment.get("orderAdjustmentTypeId"))) {
+                                for (GenericValue shipGroupItemAdjustment : shipGroupItemAdjustments) {
+                                    if ("SALES_TAX".equals(shipGroupItemAdjustment.get("orderAdjustmentTypeId")) ||
+                                            "VAT_TAX".equals(shipGroupItemAdjustment.get("orderAdjustmentTypeId")) ||
+                                            "VAT_PRICE_CORRECT".equals(shipGroupItemAdjustment.get("orderAdjustmentTypeId"))) {
                                         itemTaxAdj.add(shipGroupItemAdjustment);
                                         continue;
                                     }