Author: jleroux
Date: Tue Feb 24 08:22:25 2015 New Revision: 1661863 URL: http://svn.apache.org/r1661863 Log: "Applied fix from trunk for revision: 1661862 " ------------------------------------------------------------------------ r1661862 | jleroux | 2015-02-24 09:21:21 +0100 (mar., 24 févr. 2015) | 5 lines 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/release14.12/ (props changed) ofbiz/branches/release14.12/applications/order/config/OrderErrorUiLabels.xml ofbiz/branches/release14.12/applications/order/src/org/ofbiz/order/order/OrderServices.java ofbiz/branches/release14.12/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java ofbiz/branches/release14.12/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartHelper.java Propchange: ofbiz/branches/release14.12/ ------------------------------------------------------------------------------ --- svn:mergeinfo (original) +++ svn:mergeinfo Tue Feb 24 08:22:25 2015 @@ -8,4 +8,4 @@ /ofbiz/branches/json-integration-refactoring:1634077-1635900 /ofbiz/branches/multitenant20100310:921280-927264 /ofbiz/branches/release13.07:1547657 -/ofbiz/trunk:1649393,1649742,1650240,1650583,1650642,1650678,1650882,1650887,1650938,1651593,1652361,1652706,1652725,1652731,1652739,1653248,1653456,1654175,1654273,1654509,1655046,1655668,1655979,1656185,1656198,1656445,1656983,1657323,1657506-1657507,1657514,1657714,1657790,1657848,1658364,1658662,1658882,1659224,1660031,1660053,1660389,1660444,1660579,1661303,1661328,1661778,1661853 +/ofbiz/trunk:1649393,1649742,1650240,1650583,1650642,1650678,1650882,1650887,1650938,1651593,1652361,1652706,1652725,1652731,1652739,1653248,1653456,1654175,1654273,1654509,1655046,1655668,1655979,1656185,1656198,1656445,1656983,1657323,1657506-1657507,1657514,1657714,1657790,1657848,1658364,1658662,1658882,1659224,1660031,1660053,1660389,1660444,1660579,1661303,1661328,1661778,1661853,1661862 Modified: ofbiz/branches/release14.12/applications/order/config/OrderErrorUiLabels.xml URL: http://svn.apache.org/viewvc/ofbiz/branches/release14.12/applications/order/config/OrderErrorUiLabels.xml?rev=1661863&r1=1661862&r2=1661863&view=diff ============================================================================== --- ofbiz/branches/release14.12/applications/order/config/OrderErrorUiLabels.xml (original) +++ ofbiz/branches/release14.12/applications/order/config/OrderErrorUiLabels.xml Tue Feb 24 08:22:25 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/branches/release14.12/applications/order/src/org/ofbiz/order/order/OrderServices.java URL: http://svn.apache.org/viewvc/ofbiz/branches/release14.12/applications/order/src/org/ofbiz/order/order/OrderServices.java?rev=1661863&r1=1661862&r2=1661863&view=diff ============================================================================== --- ofbiz/branches/release14.12/applications/order/src/org/ofbiz/order/order/OrderServices.java (original) +++ ofbiz/branches/release14.12/applications/order/src/org/ofbiz/order/order/OrderServices.java Tue Feb 24 08:22:25 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/branches/release14.12/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java URL: http://svn.apache.org/viewvc/ofbiz/branches/release14.12/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java?rev=1661863&r1=1661862&r2=1661863&view=diff ============================================================================== --- ofbiz/branches/release14.12/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java (original) +++ ofbiz/branches/release14.12/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java Tue Feb 24 08:22:25 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/branches/release14.12/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartHelper.java URL: http://svn.apache.org/viewvc/ofbiz/branches/release14.12/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartHelper.java?rev=1661863&r1=1661862&r2=1661863&view=diff ============================================================================== --- ofbiz/branches/release14.12/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartHelper.java (original) +++ ofbiz/branches/release14.12/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartHelper.java Tue Feb 24 08:22:25 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 { |
Free forum by Nabble | Edit this page |