You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ja...@apache.org on 2007/03/12 12:38:11 UTC

svn commit: r517183 - in /ofbiz/trunk/applications/order: script/org/ofbiz/order/order/ servicedef/ src/org/ofbiz/order/order/ src/org/ofbiz/order/shoppingcart/ src/org/ofbiz/order/shoppingcart/product/

Author: jacopoc
Date: Mon Mar 12 04:38:10 2007
New Revision: 517183

URL: http://svn.apache.org/viewvc?view=rev&rev=517183
Log:
Fixed bug that was preventing the cancellation of an order item if the the ATP of the item was 0 or if the discontinuation date was passed.
Fixed by adding two optional parameters to the loadCartFromOrder (and to the ShoppingCart* methods as well) to skip the checks for inventory and discontinuation date while loading the cart in memory.
This should also help to fix OFBIZ-501.

Modified:
    ofbiz/trunk/applications/order/script/org/ofbiz/order/order/OrderServices.xml
    ofbiz/trunk/applications/order/servicedef/services_cart.xml
    ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java
    ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java
    ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartItem.java
    ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartServices.java
    ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/product/ProductPromoWorker.java

Modified: ofbiz/trunk/applications/order/script/org/ofbiz/order/order/OrderServices.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/script/org/ofbiz/order/order/OrderServices.xml?view=diff&rev=517183&r1=517182&r2=517183
==============================================================================
--- ofbiz/trunk/applications/order/script/org/ofbiz/order/order/OrderServices.xml (original)
+++ ofbiz/trunk/applications/order/script/org/ofbiz/order/order/OrderServices.xml Mon Mar 12 04:38:10 2007
@@ -508,7 +508,8 @@
 
         <!-- Recalculate the promotions for the order -->
         <set-service-fields service-name="loadCartFromOrder" to-map-name="loadCartFromOrderInMap" map-name="parameters"/>
-        <!--<set value="false" field="loadCartFromOrderInMap.applyOrderAdjustments"/>-->
+        <set value="true" field="loadCartFromOrderInMap.skipInventoryChecks" type="Boolean"/>
+        <set value="true" field="loadCartFromOrderInMap.skipProductChecks" type="Boolean"/>
         <call-service service-name="loadCartFromOrder" in-map-name="loadCartFromOrderInMap">
             <result-to-field result-name="shoppingCart" field-name="cart"/>
         </call-service>

Modified: ofbiz/trunk/applications/order/servicedef/services_cart.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/servicedef/services_cart.xml?view=diff&rev=517183&r1=517182&r2=517183
==============================================================================
--- ofbiz/trunk/applications/order/servicedef/services_cart.xml (original)
+++ ofbiz/trunk/applications/order/servicedef/services_cart.xml Mon Mar 12 04:38:10 2007
@@ -97,6 +97,8 @@
             location="org.ofbiz.order.shoppingcart.ShoppingCartServices" invoke="loadCartFromOrder">
         <description>Create a ShoppingCart Object based on an existing order</description>
         <attribute name="orderId" type="String" mode="IN" optional="false"/>
+        <attribute name="skipInventoryChecks" type="Boolean" mode="IN" optional="true"/>
+        <attribute name="skipProductChecks" type="Boolean" mode="IN" optional="true"/>
         <attribute name="shoppingCart" type="org.ofbiz.order.shoppingcart.ShoppingCart" mode="OUT" optional="false"/>
     </service>
 

Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java?view=diff&rev=517183&r1=517182&r2=517183
==============================================================================
--- ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java (original)
+++ ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java Mon Mar 12 04:38:10 2007
@@ -2906,7 +2906,7 @@
 
         // add in the new product
         try {
-            ShoppingCartItem item = ShoppingCartItem.makeItem(null, productId, null, quantity.doubleValue(), null, null, null, null, null, null, null, null, prodCatalogId, null, null, null, dispatcher, cart, null, null, null);
+            ShoppingCartItem item = ShoppingCartItem.makeItem(null, productId, null, quantity.doubleValue(), null, null, null, null, null, null, null, null, prodCatalogId, null, null, null, dispatcher, cart, null, null, null, Boolean.FALSE, Boolean.FALSE);
             if (basePrice != null&&overridePrice!=null) {
                 item.setBasePrice(basePrice.doubleValue());
                 // special hack to make sure we re-calc the promos after a price change
@@ -3373,7 +3373,7 @@
             // load the order into a shopping cart
             Map loadCartResp = null;
             try {
-                loadCartResp = dispatcher.runSync("loadCartFromOrder", UtilMisc.toMap("orderId", orderId, "userLogin", userLogin));
+                loadCartResp = dispatcher.runSync("loadCartFromOrder", UtilMisc.toMap("orderId", orderId, "skipInventoryChecks", Boolean.TRUE, "skipProductChecks", Boolean.TRUE, "userLogin", userLogin));
             } catch (GenericServiceException e) {
                 return ServiceUtil.returnError(e.getMessage());
             }

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?view=diff&rev=517183&r1=517182&r2=517183
==============================================================================
--- ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java (original)
+++ ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java Mon Mar 12 04:38:10 2007
@@ -480,7 +480,7 @@
             return this.addItem(0, ShoppingCartItem.makeItem(new Integer(0), productId, selectedAmountDbl, quantity, null, 
                     reservStart, reservLengthDbl, reservPersonsDbl, shipBeforeDate, shipAfterDate, 
                     features, attributes, prodCatalogId, configWrapper, itemType, itemGroup, dispatcher, 
-                    this, Boolean.TRUE, Boolean.TRUE, parentProductId));
+                    this, Boolean.TRUE, Boolean.TRUE, parentProductId, Boolean.FALSE, Boolean.FALSE));
         }
     }
 
@@ -509,7 +509,12 @@
 
     /** Add an item to the shopping cart. */
     public int addItemToEnd(String productId, Double amount, double quantity, Double unitPrice, HashMap features, HashMap attributes, String prodCatalogId, String itemType, LocalDispatcher dispatcher, Boolean triggerExternalOps, Boolean triggerPriceRules) throws CartItemModifyException, ItemNotFoundException {
-        return addItemToEnd(ShoppingCartItem.makeItem(null, productId, amount, quantity, unitPrice, null, null, null, null, null, features, attributes, prodCatalogId, null, itemType, null, dispatcher, this, triggerExternalOps, triggerPriceRules, null));
+        return addItemToEnd(productId, amount, quantity, unitPrice, features, attributes, prodCatalogId, itemType, dispatcher, triggerExternalOps, triggerPriceRules, Boolean.FALSE, Boolean.FALSE);
+    }
+
+    /** Add an item to the shopping cart. */
+    public int addItemToEnd(String productId, Double amount, double quantity, Double unitPrice, HashMap features, HashMap attributes, String prodCatalogId, String itemType, LocalDispatcher dispatcher, Boolean triggerExternalOps, Boolean triggerPriceRules, Boolean skipInventoryChecks, Boolean skipProductChecks) throws CartItemModifyException, ItemNotFoundException {
+        return addItemToEnd(ShoppingCartItem.makeItem(null, productId, amount, quantity, unitPrice, null, null, null, null, null, features, attributes, prodCatalogId, null, itemType, null, dispatcher, this, triggerExternalOps, triggerPriceRules, null, skipInventoryChecks, skipProductChecks));
     }
 
     /** Add an item to the shopping cart. */

Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartItem.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartItem.java?view=diff&rev=517183&r1=517182&r2=517183
==============================================================================
--- ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartItem.java (original)
+++ ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartItem.java Mon Mar 12 04:38:10 2007
@@ -279,7 +279,7 @@
     public static ShoppingCartItem makeItem(Integer cartLocation, String productId, Double selectedAmountDbl, double quantity, Double unitPriceDbl, 
             Timestamp reservStart, Double reservLengthDbl, Double reservPersonsDbl, Timestamp shipBeforeDate, Timestamp shipAfterDate, 
             Map additionalProductFeatureAndAppls, Map attributes, String prodCatalogId, ProductConfigWrapper configWrapper, 
-            String itemType, ShoppingCart.ShoppingCartItemGroup itemGroup, LocalDispatcher dispatcher, ShoppingCart cart, Boolean triggerExternalOpsBool, Boolean triggerPriceRulesBool, String parentProductId) 
+            String itemType, ShoppingCart.ShoppingCartItemGroup itemGroup, LocalDispatcher dispatcher, ShoppingCart cart, Boolean triggerExternalOpsBool, Boolean triggerPriceRulesBool, String parentProductId, Boolean skipInventoryChecks, Boolean skipProductChecks) 
             throws CartItemModifyException, ItemNotFoundException {
         GenericDelegator delegator = cart.getDelegator();
         GenericValue product = null;
@@ -322,7 +322,7 @@
         return makeItem(cartLocation, product, selectedAmountDbl, quantity, unitPriceDbl, 
                 reservStart, reservLengthDbl, reservPersonsDbl, shipBeforeDate, shipAfterDate, 
                 additionalProductFeatureAndAppls, attributes, prodCatalogId, configWrapper, 
-                itemType, itemGroup, dispatcher, cart, triggerExternalOpsBool, triggerPriceRulesBool, parentProduct);
+                itemType, itemGroup, dispatcher, cart, triggerExternalOpsBool, triggerPriceRulesBool, parentProduct, skipInventoryChecks, skipProductChecks);
     }
 
     /**
@@ -358,7 +358,7 @@
             double quantity, Double unitPriceDbl, Timestamp reservStart, Double reservLengthDbl, Double reservPersonsDbl, 
             Timestamp shipBeforeDate, Timestamp shipAfterDate, Map additionalProductFeatureAndAppls, Map attributes, 
             String prodCatalogId, ProductConfigWrapper configWrapper, String itemType, ShoppingCart.ShoppingCartItemGroup itemGroup, LocalDispatcher dispatcher, 
-            ShoppingCart cart, Boolean triggerExternalOpsBool, Boolean triggerPriceRulesBool, GenericValue parentProduct) throws CartItemModifyException {
+            ShoppingCart cart, Boolean triggerExternalOpsBool, Boolean triggerPriceRulesBool, GenericValue parentProduct, Boolean skipInventoryChecks, Boolean skipProductChecks) throws CartItemModifyException {
 
         ShoppingCartItem newItem = new ShoppingCartItem(product, additionalProductFeatureAndAppls, attributes, prodCatalogId, configWrapper, cart.getLocale(), itemType, itemGroup, parentProduct);
 
@@ -383,30 +383,48 @@
 
         java.sql.Timestamp nowTimestamp = UtilDateTime.nowTimestamp();
         
-        // check to see if introductionDate hasn't passed yet
-        if (product.get("introductionDate") != null && nowTimestamp.before(product.getTimestamp("introductionDate"))) {
-            Map messageMap = UtilMisc.toMap("productName", product.getString("productName"), 
-                                            "productId", product.getString("productId"));            
+        if (!skipProductChecks.booleanValue()) {
+            // check to see if introductionDate hasn't passed yet
+            if (product.get("introductionDate") != null && nowTimestamp.before(product.getTimestamp("introductionDate"))) {
+                Map messageMap = UtilMisc.toMap("productName", product.getString("productName"), 
+                                                "productId", product.getString("productId"));            
 
-            String excMsg = UtilProperties.getMessage(resource, "item.cannot_add_product_not_yet_available",
-                                          messageMap , cart.getLocale() );            
-            
-            Debug.logWarning(excMsg, module);
-            throw new CartItemModifyException(excMsg);
-        }
-        
-        // check to see if salesDiscontinuationDate has passed
-        if (product.get("salesDiscontinuationDate") != null && nowTimestamp.after(product.getTimestamp("salesDiscontinuationDate"))) {
-            Map messageMap = UtilMisc.toMap("productName", product.getString("productName"), 
-                                            "productId", product.getString("productId"));            
+                String excMsg = UtilProperties.getMessage(resource, "item.cannot_add_product_not_yet_available",
+                                              messageMap , cart.getLocale() );            
 
-            String excMsg = UtilProperties.getMessage(resource, "item.cannot_add_product_no_longer_available",
-                                          messageMap , cart.getLocale() );
+                Debug.logWarning(excMsg, module);
+                throw new CartItemModifyException(excMsg);
+            }
 
-            Debug.logWarning(excMsg, module);
-            throw new CartItemModifyException(excMsg);
+            // check to see if salesDiscontinuationDate has passed
+            if (product.get("salesDiscontinuationDate") != null && nowTimestamp.after(product.getTimestamp("salesDiscontinuationDate"))) {
+                Map messageMap = UtilMisc.toMap("productName", product.getString("productName"), 
+                                                "productId", product.getString("productId"));
+
+                String excMsg = UtilProperties.getMessage(resource, "item.cannot_add_product_no_longer_available",
+                                              messageMap , cart.getLocale() );
+
+                Debug.logWarning(excMsg, module);
+                throw new CartItemModifyException(excMsg);
+            }
+            /*
+            if (product.get("salesDiscWhenNotAvail") != null && "Y".equals(product.getString("salesDiscWhenNotAvail"))) {
+                // check atp and if <= 0 then the product is no more available because
+                // all the units in warehouse are reserved by other sales orders and no new purchase orders will be done 
+                // for this product.
+                if (!newItem.isInventoryAvailableOrNotRequired(quantity, cart.getProductStoreId(), dispatcher)) {
+                    Map messageMap = UtilMisc.toMap("productName", product.getString("productName"), 
+                                                    "productId", product.getString("productId"));
+
+                    String excMsg = UtilProperties.getMessage(resource, "item.cannot_add_product_no_longer_available",
+                                                  messageMap , cart.getLocale() );
+
+                    Debug.logWarning(excMsg, module);
+                    throw new CartItemModifyException(excMsg);
+                }
+            }
+             */
         }
- 
         // check to see if the product is a rental item
         if ("ASSET_USAGE".equals(product.getString("productTypeId"))) {
             if (reservStart == null)    {
@@ -496,7 +514,7 @@
         }
 
         try {
-            newItem.setQuantity(quantity, dispatcher, cart, triggerExternalOps, true, triggerPriceRules);
+            newItem.setQuantity((int)quantity, dispatcher, cart, triggerExternalOps, true, triggerPriceRules, skipInventoryChecks.booleanValue());
         } catch (CartItemModifyException e) {
             Debug.logWarning(e.getMessage(), module);
             cart.removeCartItem(cart.getItemIndex(newItem), dispatcher);
@@ -755,12 +773,12 @@
 
     /** Sets the quantity for the item and validates the change in quantity, etc */
     public void setQuantity(double quantity, LocalDispatcher dispatcher, ShoppingCart cart, boolean triggerExternalOps, boolean resetShipGroup) throws CartItemModifyException {
-        this.setQuantity((int) quantity, dispatcher, cart, triggerExternalOps, resetShipGroup, true);
+        this.setQuantity((int) quantity, dispatcher, cart, triggerExternalOps, resetShipGroup, true, false);
     }
 
     /** Sets the quantity for the item and validates the change in quantity, etc */
     public void setQuantity(double quantity, LocalDispatcher dispatcher, ShoppingCart cart, boolean triggerExternalOps, boolean resetShipGroup, boolean updateProductPrice) throws CartItemModifyException {
-        this.setQuantity((int) quantity, dispatcher, cart, triggerExternalOps, resetShipGroup, updateProductPrice);
+        this.setQuantity((int) quantity, dispatcher, cart, triggerExternalOps, resetShipGroup, updateProductPrice, false);
     }
 
     /** returns "OK" when the product can be booked or returns a string with the dates the related fixed Asset is not available */
@@ -869,7 +887,24 @@
         }
     }
 
-    protected void setQuantity(int quantity, LocalDispatcher dispatcher, ShoppingCart cart, boolean triggerExternalOps, boolean resetShipGroup, boolean updateProductPrice) throws CartItemModifyException {
+    protected boolean isInventoryAvailableOrNotRequired(double quantity, String productStoreId, LocalDispatcher dispatcher) throws CartItemModifyException {
+        boolean inventoryAvailable = true;
+        try {
+            Map invReqResult = dispatcher.runSync("isStoreInventoryAvailableOrNotRequired", UtilMisc.toMap("productStoreId", productStoreId, "productId", productId, "product", this.getProduct(), "quantity", new Double(quantity)));
+            if (ServiceUtil.isError(invReqResult)) {
+                Debug.logError("Error calling isStoreInventoryAvailableOrNotRequired service, result is: " + invReqResult, module);
+                throw new CartItemModifyException((String) invReqResult.get(ModelService.ERROR_MESSAGE));
+            }
+            inventoryAvailable = "Y".equals((String) invReqResult.get("availableOrNotRequired"));
+        } catch (GenericServiceException e) {
+            String errMsg = "Fatal error calling inventory checking services: " + e.toString();
+            Debug.logError(e, errMsg, module);
+            throw new CartItemModifyException(errMsg);
+        }
+        return inventoryAvailable;
+    }
+
+    protected void setQuantity(int quantity, LocalDispatcher dispatcher, ShoppingCart cart, boolean triggerExternalOps, boolean resetShipGroup, boolean updateProductPrice, boolean skipInventoryChecks) throws CartItemModifyException {
         if (this.quantity == quantity) {
             return;
         }
@@ -881,23 +916,13 @@
         // needed for inventory checking and auto-save
         String productStoreId = cart.getProductStoreId();
 
-        if (!"PURCHASE_ORDER".equals(cart.getOrderType())) {
+        if (!skipInventoryChecks && !"PURCHASE_ORDER".equals(cart.getOrderType())) {
             // check inventory if new quantity is greater than old quantity; don't worry about inventory getting pulled out from under, that will be handled at checkout time
             if (_product != null && quantity > this.quantity) {
-                try {
-                    Map invReqResult = dispatcher.runSync("isStoreInventoryAvailableOrNotRequired", UtilMisc.toMap("productStoreId", productStoreId, "productId", productId, "product", this.getProduct(), "quantity", new Double(quantity)));
-                    if (ServiceUtil.isError(invReqResult)) {
-                        Debug.logError("Error calling isStoreInventoryAvailableOrNotRequired service, result is: " + invReqResult, module);
-                        throw new CartItemModifyException((String) invReqResult.get(ModelService.ERROR_MESSAGE));
-                    } else if (!"Y".equals((String) invReqResult.get("availableOrNotRequired"))) {
-                        String excMsg = "Sorry, we do not have enough (you tried " + UtilFormatOut.formatQuantity(quantity) + ") of the product " + this.getName() + " (product ID: " + productId + ") in stock, not adding to cart. Please try a lower quantity, try again later, or call customer service for more information.";
-                        Debug.logWarning(excMsg, module);
-                        throw new CartItemModifyException(excMsg);
-                    }
-                } catch (GenericServiceException e) {
-                    String errMsg = "Fatal error calling inventory checking services: " + e.toString();
-                    Debug.logError(e, errMsg, module);
-                    throw new CartItemModifyException(errMsg);
+                if (!isInventoryAvailableOrNotRequired(quantity, productStoreId, dispatcher)) {
+                    String excMsg = "Sorry, we do not have enough (you tried " + UtilFormatOut.formatQuantity(quantity) + ") of the product " + this.getName() + " (product ID: " + productId + ") in stock, not adding to cart. Please try a lower quantity, try again later, or call customer service for more information.";
+                    Debug.logWarning(excMsg, module);
+                    throw new CartItemModifyException(excMsg);
                 }
             }
         }

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?view=diff&rev=517183&r1=517182&r2=517183
==============================================================================
--- ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartServices.java (original)
+++ ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartServices.java Mon Mar 12 04:38:10 2007
@@ -149,8 +149,17 @@
 
         GenericValue userLogin = (GenericValue) context.get("userLogin");
         String orderId = (String) context.get("orderId");
+        Boolean skipInventoryChecks = (Boolean) context.get("skipInventoryChecks");
+        Boolean skipProductChecks = (Boolean) context.get("skipProductChecks");
         Locale locale = (Locale) context.get("locale");
 
+        if (UtilValidate.isEmpty(skipInventoryChecks)) {
+            skipInventoryChecks = Boolean.FALSE;
+        }
+        if (UtilValidate.isEmpty(skipProductChecks)) {
+            skipProductChecks = Boolean.FALSE;
+        }
+
         // get the order header
         GenericValue orderHeader = null;
         try {
@@ -293,7 +302,7 @@
                     String prodCatalogId = item.getString("prodCatalogId");
                     String productId = item.getString("productId");
                     try {
-                        itemIndex = cart.addItemToEnd(productId, amount, quantityDbl, null, null, null, prodCatalogId, item.getString("orderItemTypeId"), dispatcher, null, null);
+                        itemIndex = cart.addItemToEnd(productId, amount, quantityDbl, null, null, null, prodCatalogId, item.getString("orderItemTypeId"), dispatcher, null, null, skipInventoryChecks, skipProductChecks);
                     } catch (ItemNotFoundException e) {
                         Debug.logError(e, module);
                         return ServiceUtil.returnError(e.getMessage());

Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/product/ProductPromoWorker.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/product/ProductPromoWorker.java?view=diff&rev=517183&r1=517182&r2=517183
==============================================================================
--- ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/product/ProductPromoWorker.java (original)
+++ ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/product/ProductPromoWorker.java Mon Mar 12 04:38:10 2007
@@ -1167,7 +1167,7 @@
                 try {
                     // just leave the prodCatalogId null, this line won't be associated with a catalog
                     String prodCatalogId = null;
-                    gwpItem = ShoppingCartItem.makeItem(null, product, null, quantity, null, null, null, null, null, null, null, null, prodCatalogId, null, null, null, dispatcher, cart, Boolean.FALSE, Boolean.TRUE, null);
+                    gwpItem = ShoppingCartItem.makeItem(null, product, null, quantity, null, null, null, null, null, null, null, null, prodCatalogId, null, null, null, dispatcher, cart, Boolean.FALSE, Boolean.TRUE, null, Boolean.FALSE, Boolean.FALSE);
                     if (optionProductIds.size() > 0) {
                         gwpItem.setAlternativeOptionProductIds(optionProductIds);
                     } else {