Author: jleroux
Date: Tue Feb 24 08:25:00 2015 New Revision: 1661864 URL: http://svn.apache.org/r1661864 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/branches/release13.07/applications/order/config/OrderErrorUiLabels.xml ofbiz/branches/release13.07/applications/order/src/org/ofbiz/order/order/OrderServices.java ofbiz/branches/release13.07/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java ofbiz/branches/release13.07/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartHelper.java Modified: ofbiz/branches/release13.07/applications/order/config/OrderErrorUiLabels.xml URL: http://svn.apache.org/viewvc/ofbiz/branches/release13.07/applications/order/config/OrderErrorUiLabels.xml?rev=1661864&r1=1661863&r2=1661864&view=diff ============================================================================== --- ofbiz/branches/release13.07/applications/order/config/OrderErrorUiLabels.xml (original) +++ ofbiz/branches/release13.07/applications/order/config/OrderErrorUiLabels.xml Tue Feb 24 08:25:00 2015 @@ -4771,6 +4771,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/branches/release13.07/applications/order/src/org/ofbiz/order/order/OrderServices.java URL: http://svn.apache.org/viewvc/ofbiz/branches/release13.07/applications/order/src/org/ofbiz/order/order/OrderServices.java?rev=1661864&r1=1661863&r2=1661864&view=diff ============================================================================== --- ofbiz/branches/release13.07/applications/order/src/org/ofbiz/order/order/OrderServices.java (original) +++ ofbiz/branches/release13.07/applications/order/src/org/ofbiz/order/order/OrderServices.java Tue Feb 24 08:25:00 2015 @@ -3544,6 +3544,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; + } + // add in the new product try { ShoppingCartItem item = null; @@ -3697,6 +3714,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) @@ -3830,6 +3864,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; + } Debug.logInfo("Shipping info (before) for group #" + (groupIdx-1) + " [" + cart.getShipmentMethodTypeId(groupIdx-1) + " / " + cart.getCarrierPartyId(groupIdx-1) + "]", module); cart.setItemShipGroupQty(cartItem, groupQty, groupIdx - 1); Debug.logInfo("Set ship group qty: [" + itemInfo[0] + " / " + itemInfo[1] + " (" + (groupIdx-1) + ")] " + groupQty, module); Modified: ofbiz/branches/release13.07/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java URL: http://svn.apache.org/viewvc/ofbiz/branches/release13.07/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java?rev=1661864&r1=1661863&r2=1661864&view=diff ============================================================================== --- ofbiz/branches/release13.07/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java (original) +++ ofbiz/branches/release13.07/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java Tue Feb 24 08:25:00 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 { @@ -1812,6 +1818,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/branches/release13.07/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartHelper.java URL: http://svn.apache.org/viewvc/ofbiz/branches/release13.07/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartHelper.java?rev=1661864&r1=1661863&r2=1661864&view=diff ============================================================================== --- ofbiz/branches/release13.07/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartHelper.java (original) +++ ofbiz/branches/release13.07/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartHelper.java Tue Feb 24 08:25:00 2015 @@ -444,7 +444,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); @@ -534,6 +554,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); @@ -748,8 +769,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 { |
Free forum by Nabble | Edit this page |