Author: jleroux
Date: Tue Feb 24 08:21:21 2015
New Revision: 1661862

URL: http://svn.apache.org/r1661862
Log:
A patch from  Deepak Dixit for "If orderDecimalQuantity set to N then system 
should return error if user add partial quantity in order" 
https://issues.apache.org/jira/browse/OFBIZ-5962

If productStore.orderDecimalQuantity OR product.orderDecimalQuantity is set to 
N, then system should return error if we try to add to partial quantity then 
system should return error instead of rounding it to 0, 
Actual Behavior: If partial quantity is not allowed in order process, and user 
enter 1.5 quantity then it rounded it and add 2 quantity.
Expected Behavior: if partial quantity is not allowed then system should return 
error instead of doing rounding if partial quantity passed during add/update 
item.

Modified:
    ofbiz/trunk/applications/order/config/OrderErrorUiLabels.xml
    ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java
    
ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java
    
ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartHelper.java

Modified: ofbiz/trunk/applications/order/config/OrderErrorUiLabels.xml
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/config/OrderErrorUiLabels.xml?rev=1661862&r1=1661861&r2=1661862&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/config/OrderErrorUiLabels.xml (original)
+++ ofbiz/trunk/applications/order/config/OrderErrorUiLabels.xml Tue Feb 24 
08:21:21 2015
@@ -4813,6 +4813,9 @@
         <value xml:lang="zh-CN">配置无效</value>
         <value xml:lang="zh-TW">配置無效</value>
     </property>
+    <property key="cart.addToCart.quantityInDecimalNotAllowed">
+        <value xml:lang="en">Quantity in decimal is not allowed.</value>
+    </property>
     <property key="cart.addToCart.rental.endDate">
         <value xml:lang="de">Probleme beim Verarbeiten der 
Reservierungszeichenkette.</value>
         <value xml:lang="en">Problems parsing Reservation end string.</value>

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?rev=1661862&r1=1661861&r2=1661862&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java 
(original)
+++ ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java 
Tue Feb 24 08:21:21 2015
@@ -3591,6 +3591,23 @@ public class OrderServices {
                     "OrderShoppingCartEmpty", locale));
         }
 
+        try {
+            //For quantity we should test if we allow to add decimal quantity 
for this product an productStore : 
+            // if not and if quantity is in decimal format then return error.
+            if(! ProductWorker.isDecimalQuantityOrderAllowed(delegator, 
productId, cart.getProductStoreId())){
+                BigDecimal remainder = quantity.remainder(BigDecimal.ONE);
+                if (remainder.compareTo(BigDecimal.ZERO) != 0) {
+                    return 
ServiceUtil.returnError(UtilProperties.getMessage(resource_error, 
"cart.addToCart.quantityInDecimalNotAllowed", locale));
+                }
+                quantity = quantity.setScale(0, 
UtilNumber.getBigDecimalRoundingMode("order.rounding"));
+            } else {
+                quantity = 
quantity.setScale(UtilNumber.getBigDecimalScale("order.decimals"), 
UtilNumber.getBigDecimalRoundingMode("order.rounding"));
+            }
+        } catch(GenericEntityException e) {
+            Debug.logError(e.getMessage(), module);
+            quantity = BigDecimal.ONE;
+        }
+
         shipGroupIdx = cart.getShipInfoIndex(shipGroupSeqId);
 
         // add in the new product
@@ -3749,6 +3766,23 @@ public class OrderServices {
                 BigDecimal qty = itemTotals.get(itemSeqId);
                 BigDecimal priceSave = cartItem.getBasePrice();
 
+                try {
+                    //For quantity we should test if we allow to add decimal 
quantity for this product an productStore : 
+                    // if not and if quantity is in decimal format then return 
error.
+                    if(! 
ProductWorker.isDecimalQuantityOrderAllowed(delegator, cartItem.getProductId(), 
cart.getProductStoreId())){
+                        BigDecimal remainder = qty.remainder(BigDecimal.ONE);
+                        if (remainder.compareTo(BigDecimal.ZERO) != 0) {
+                            return 
ServiceUtil.returnError(UtilProperties.getMessage(resource_error, 
"cart.addToCart.quantityInDecimalNotAllowed", locale));
+                        }
+                        qty = qty.setScale(0, 
UtilNumber.getBigDecimalRoundingMode("order.rounding"));
+                    } else {
+                        qty = 
qty.setScale(UtilNumber.getBigDecimalScale("order.decimals"), 
UtilNumber.getBigDecimalRoundingMode("order.rounding"));
+                    }
+                } catch(GenericEntityException e) {
+                    Debug.logError(e.getMessage(), module);
+                    qty = BigDecimal.ONE;
+                }
+
                 // set quantity
                 try {
                     cartItem.setQuantity(qty, dispatcher, cart, false, false); 
// trigger external ops, don't reset ship groups (and update prices for both PO 
and SO items)
@@ -3881,6 +3915,22 @@ public class OrderServices {
             // set the group qty
             ShoppingCartItem cartItem = cart.findCartItem(itemInfo[0]);
             if (cartItem != null) {
+                try {
+                    //For quantity we should test if we allow to add decimal 
quantity for this product an productStore : 
+                    // if not and if quantity is in decimal format then return 
error.
+                    if(! 
ProductWorker.isDecimalQuantityOrderAllowed(delegator, cartItem.getProductId(), 
cart.getProductStoreId())){
+                        BigDecimal remainder = 
groupQty.remainder(BigDecimal.ONE);
+                        if (remainder.compareTo(BigDecimal.ZERO) != 0) {
+                            return 
ServiceUtil.returnError(UtilProperties.getMessage(resource_error, 
"cart.addToCart.quantityInDecimalNotAllowed", locale));
+                        }
+                        groupQty = groupQty.setScale(0, 
UtilNumber.getBigDecimalRoundingMode("order.rounding"));
+                    } else {
+                        groupQty = 
groupQty.setScale(UtilNumber.getBigDecimalScale("order.decimals"), 
UtilNumber.getBigDecimalRoundingMode("order.rounding"));
+                    }
+                } catch(GenericEntityException e) {
+                    Debug.logError(e.getMessage(), module);
+                    groupQty = BigDecimal.ONE;
+                }
                 int shipGroupIndex = cart.getShipInfoIndex(itemInfo[1]);
                 if (Debug.infoOn()) Debug.logInfo("Shipping info (before) for 
group #" + (shipGroupIndex) + " [" + 
cart.getShipmentMethodTypeId(shipGroupIndex) + " / " + 
cart.getCarrierPartyId(shipGroupIndex) + "]", module);
                 cart.setItemShipGroupQty(cartItem, groupQty, shipGroupIndex);

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=1661862&r1=1661861&r2=1661862&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
 Tue Feb 24 08:21:21 2015
@@ -464,8 +464,14 @@ public class ShoppingCartEvents {
         // parse the quantity
         try {
             quantity = (BigDecimal) ObjectType.simpleTypeConvert(quantityStr, 
"BigDecimal", null, locale);
-            //For quantity we should test if we allow to add decimal quantity 
for this product an productStore : if not then round to 0
+            //For quantity we should test if we allow to add decimal quantity 
for this product an productStore : 
+            // if not and if quantity is in decimal format then return error.
             if(! ProductWorker.isDecimalQuantityOrderAllowed(delegator, 
productId, cart.getProductStoreId())){
+                BigDecimal remainder = quantity.remainder(BigDecimal.ONE);
+                if (remainder.compareTo(BigDecimal.ZERO) != 0) {
+                    request.setAttribute("_ERROR_MESSAGE_", 
UtilProperties.getMessage(resource_error, 
"cart.addToCart.quantityInDecimalNotAllowed", locale));
+                    return "error";
+                }
                 quantity = quantity.setScale(0, 
UtilNumber.getBigDecimalRoundingMode("order.rounding"));
             }
             else {
@@ -1809,6 +1815,25 @@ public class ShoppingCartEvents {
                     quantity = BigDecimal.ZERO;
                 }
 
+                try {
+                    //For quantity we should test if we allow to add decimal 
quantity for this product an productStore : 
+                    // if not and if quantity is in decimal format then return 
error.
+                    if(! 
ProductWorker.isDecimalQuantityOrderAllowed(delegator, productId, 
cart.getProductStoreId())){
+                        BigDecimal remainder = 
quantity.remainder(BigDecimal.ONE);
+                        if (remainder.compareTo(BigDecimal.ZERO) != 0) {
+                            request.setAttribute("_ERROR_MESSAGE_", 
UtilProperties.getMessage(resource_error, 
"cart.addToCart.quantityInDecimalNotAllowed", cart.getLocale()));
+                            return "error";
+                        }
+                        quantity = quantity.setScale(0, 
UtilNumber.getBigDecimalRoundingMode("order.rounding"));
+                    }
+                    else {
+                        quantity = 
quantity.setScale(UtilNumber.getBigDecimalScale("order.decimals"), 
UtilNumber.getBigDecimalRoundingMode("order.rounding"));
+                    }
+                } catch (GenericEntityException e) {
+                    Debug.logWarning(e.getMessage(), module);
+                    quantity = BigDecimal.ONE;
+                }
+
                 // get the selected amount
                 String selectedAmountStr = null;
                 if (paramMap.containsKey("amount" + thisSuffix)) {

Modified: 
ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartHelper.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartHelper.java?rev=1661862&r1=1661861&r2=1661862&view=diff
==============================================================================
--- 
ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartHelper.java
 (original)
+++ 
ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartHelper.java
 Tue Feb 24 08:21:21 2015
@@ -446,7 +446,27 @@ public class ShoppingCartHelper {
                             quantity = quantity.multiply(piecesIncluded);
                         }
                     }
-                    
+
+                    try {
+                        //For quantity we should test if we allow to add 
decimal quantity for this product an productStore : 
+                        // if not and if quantity is in decimal format then 
return error.
+                        if(! 
ProductWorker.isDecimalQuantityOrderAllowed(delegator, productId, 
cart.getProductStoreId())){
+                            BigDecimal remainder = 
quantity.remainder(BigDecimal.ONE);
+                            if (remainder.compareTo(BigDecimal.ZERO) != 0) {
+                                return 
ServiceUtil.returnError(UtilProperties.getMessage(resource_error, 
"cart.addToCart.quantityInDecimalNotAllowed", this.cart.getLocale()));
+                            }
+                            quantity = quantity.setScale(0, 
UtilNumber.getBigDecimalRoundingMode("order.rounding"));
+                        } else {
+                            quantity = 
quantity.setScale(UtilNumber.getBigDecimalScale("order.decimals"), 
UtilNumber.getBigDecimalRoundingMode("order.rounding"));
+                        }
+                    } catch(GenericEntityException e) {
+                        Debug.logError(e.getMessage(), module);
+                        quantity = BigDecimal.ONE;
+                    }
+                    if (quantity.compareTo(BigDecimal.ZERO) < 0) {
+                        return 
ServiceUtil.returnError(UtilProperties.getMessage(resource_error, 
"cart.quantity_not_positive_number", this.cart.getLocale()));
+                    }
+
                     try {
                         if (Debug.verboseOn()) Debug.logVerbose("Bulk Adding 
to cart [" + quantity + "] of [" + productId + "] in Item Group [" + 
itemGroupNumber + "]", module);
                         this.cart.addOrIncreaseItem(productId, null, quantity, 
null, null, null, null, null, null, null, catalogId, null, null, 
itemGroupNumberToUse, originalProductId, dispatcher);
@@ -536,6 +556,7 @@ public class ShoppingCartHelper {
                             if (Debug.warningOn()) 
Debug.logWarning(UtilProperties.getMessage(resource_error, 
"OrderTheRequirementIsAlreadyInTheCartNotAdding", 
UtilMisc.toMap("requirementId",requirementId), cart.getLocale()), module);
                             continue;
                         }
+
                         try {
                             if (Debug.verboseOn()) Debug.logVerbose("Bulk 
Adding to cart requirement [" + quantity + "] of [" + productId + "]", module);
                             int index = this.cart.addOrIncreaseItem(productId, 
null, quantity, null, null, null, requirement.getTimestamp("requiredByDate"), 
null, null, null, catalogId, null, null, itemGroupNumber, null, dispatcher);
@@ -750,8 +771,16 @@ public class ShoppingCartHelper {
                         }
                     } else {
                         quantity = (BigDecimal) 
ObjectType.simpleTypeConvert(quantString, "BigDecimal", null, locale);
-                        //For quantity we should test if we allow to add 
decimal quantity for this product an productStore : if not then round to 0
+                        //For quantity we should test if we allow to add 
decimal quantity for this product an productStore : 
+                        // if not and if quantity is in decimal format then 
return error.
                         if(! 
ProductWorker.isDecimalQuantityOrderAllowed(delegator, item.getProductId(), 
cart.getProductStoreId())){
+                            BigDecimal remainder = 
quantity.remainder(BigDecimal.ONE);
+                            if (remainder.compareTo(BigDecimal.ZERO) != 0) {
+                                String errMsg = 
UtilProperties.getMessage(resource_error, 
"cart.addToCart.quantityInDecimalNotAllowed", this.cart.getLocale());
+                                errorMsgs.add(errMsg);
+                                result = ServiceUtil.returnError(errorMsgs);
+                                return result;
+                            }
                             quantity = quantity.setScale(0, 
UtilNumber.getBigDecimalRoundingMode("order.rounding"));
                         }                
                         else {


Reply via email to