Author: jleroux
Date: Sun Apr 17 09:17:21 2011 New Revision: 1094121 URL: http://svn.apache.org/viewvc?rev=1094121&view=rev Log: A patch from Pierre Gaudin "Add a parameter to forbid order decimal quantity" https://issues.apache.org/jira/browse/OFBIZ-4257 Behavior before the patch : * you can add decimal quantity on shopping cart item (front office and back office) even if the product is a unit * there is no rounding on quantity on shopping cart item thus you get amount with a large number of decimal * reorder widget display quantity to reorder with a large number of decimal What does this patch : * a new field "orderDecimalQuantity" is added into ProducStore entity. The value of this field can be set from EditProducStore form (into shopping cart section). Value can be "Y", "N" or empty. * a new field "orderDecimalQuantity" is added into Product entity. The value of this field can be set from EditProduc form (into shopping cart section). Value can be "Y", "N" or empty. * a new method "isDecimalQuantityOrderAllowed" have been add into productWorker class. This method test if order decimal quantity is allow for a product and a productStore. Product is superior on producStore. Here is the table of value : * ProductStore.orderDecimalQuantity = "Y" && Product.orderDecimalQuantity = "Y" => return True * ProductStore.orderDecimalQuantity = "N" && Product.orderDecimalQuantity = "Y" => return True * ProductStore.orderDecimalQuantity = empty && Product.orderDecimalQuantity = "Y" => return True * ProductStore.orderDecimalQuantity = "Y" && Product.orderDecimalQuantity = "N" => return False * ProductStore.orderDecimalQuantity = "N" && Product.orderDecimalQuantity = "N" => return False * ProductStore.orderDecimalQuantity = empty && Product.orderDecimalQuantity = "N" => return False * ProductStore.orderDecimalQuantity = "Y" && Product.orderDecimalQuantity = empty => return True * ProductStore.orderDecimalQuantity = "N" && Product.orderDecimalQuantity = empty => return False * ProductStore.orderDecimalQuantity = empty && Product.orderDecimalQuantity = empty => return True * addToCat and modifyCart car method have been modify to call isDecimalQuantityOrderAllowed. If result is true then quantity is rounding with order config value. If result is false then quantity is rounding to 0. No message is return. * to fix reorder quantity, then getQuickReorderProducts method have been modify to call isDecimalQuantityOrderAllowed. If result is true then quantity is rounding with order config value. If result is false then quantity is rounding to 0. What the result : * You can forbid or accept to manage order decimal quantity for all product * You can forbid or accept to manage order decimal quantity for one product * Decimal quantity are now rounded with order config value. * reorder quantity is rounded with order config value or rounding to 0 Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartHelper.java ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/product/ProductDisplayWorker.java ofbiz/trunk/applications/product/config/ProductUiLabels.xml ofbiz/trunk/applications/product/entitydef/entitymodel.xml ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductWorker.java ofbiz/trunk/applications/product/widget/catalog/ProductForms.xml ofbiz/trunk/applications/product/widget/catalog/ProductStoreForms.xml 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=1094121&r1=1094120&r2=1094121&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 Sun Apr 17 09:17:21 2011 @@ -43,6 +43,7 @@ import org.ofbiz.base.util.UtilFormatOut import org.ofbiz.base.util.UtilGenerics; import org.ofbiz.base.util.UtilHttp; import org.ofbiz.base.util.UtilMisc; +import org.ofbiz.base.util.UtilNumber; import org.ofbiz.base.util.UtilProperties; import org.ofbiz.base.util.UtilValidate; import org.ofbiz.entity.Delegator; @@ -400,6 +401,13 @@ 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 + if(! ProductWorker.isDecimalQuantityOrderAllowed(delegator, productId, cart.getProductStoreId())){ + quantity = quantity.setScale(0, UtilNumber.getBigDecimalRoundingMode("order.rounding")); + } + else { + quantity = quantity.setScale(UtilNumber.getBigDecimalScale("order.decimals"), UtilNumber.getBigDecimalRoundingMode("order.rounding")); + } } catch (Exception e) { Debug.logWarning(e, "Problems parsing quantity string: " + quantityStr, module); quantity = BigDecimal.ONE; 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=1094121&r1=1094120&r2=1094121&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 Sun Apr 17 09:17:21 2011 @@ -38,6 +38,7 @@ import org.ofbiz.base.util.GeneralExcept import org.ofbiz.base.util.ObjectType; import org.ofbiz.base.util.UtilHttp; import org.ofbiz.base.util.UtilMisc; +import org.ofbiz.base.util.UtilNumber; import org.ofbiz.base.util.UtilProperties; import org.ofbiz.base.util.UtilValidate; import org.ofbiz.entity.Delegator; @@ -743,6 +744,13 @@ 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 + if(! ProductWorker.isDecimalQuantityOrderAllowed(delegator, item.getProductId(), cart.getProductStoreId())){ + quantity = quantity.setScale(0, UtilNumber.getBigDecimalRoundingMode("order.rounding")); + } + else { + quantity = quantity.setScale(UtilNumber.getBigDecimalScale("order.decimals"), UtilNumber.getBigDecimalRoundingMode("order.rounding")); + } if (quantity.compareTo(BigDecimal.ZERO) < 0) { String errMsg = UtilProperties.getMessage(resource_error, "cart.quantity_not_positive_number", this.cart.getLocale()); errorMsgs.add(errMsg); Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/product/ProductDisplayWorker.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/product/ProductDisplayWorker.java?rev=1094121&r1=1094120&r2=1094121&view=diff ============================================================================== --- ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/product/ProductDisplayWorker.java (original) +++ ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/product/ProductDisplayWorker.java Sun Apr 17 09:17:21 2011 @@ -36,6 +36,7 @@ import javolution.util.FastMap; import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.UtilGenerics; import org.ofbiz.base.util.UtilMisc; +import org.ofbiz.base.util.UtilNumber; import org.ofbiz.base.util.UtilValidate; import org.ofbiz.entity.Delegator; import org.ofbiz.entity.GenericEntity; @@ -46,6 +47,7 @@ import org.ofbiz.order.shoppingcart.Shop import org.ofbiz.order.shoppingcart.ShoppingCartItem; import org.ofbiz.product.catalog.CatalogWorker; import org.ofbiz.product.category.CategoryWorker; +import org.ofbiz.product.product.ProductWorker; public class ProductDisplayWorker { @@ -282,6 +284,14 @@ public class ProductDisplayWorker { String prodId = entry.getKey(); Integer quantity = entry.getValue(); BigDecimal occs = productQuantities.get(prodId); + //For quantity we should test if we allow to add decimal quantity for this product an productStore : if not then round to 0 + if(! ProductWorker.isDecimalQuantityOrderAllowed(delegator, (String)prodId, cart.getProductStoreId())){ + occs = occs.setScale(0, UtilNumber.getBigDecimalRoundingMode("order.rounding")); + } + else { + occs = occs.setScale(UtilNumber.getBigDecimalScale("order.decimals"), UtilNumber.getBigDecimalRoundingMode("order.rounding")); + } + productQuantities.put(prodId, occs); BigDecimal nqdbl = quantityModifier.multiply(new BigDecimal(quantity)).add(occs.multiply(occurancesModifier)); newMetric.put(prodId, nqdbl); Modified: ofbiz/trunk/applications/product/config/ProductUiLabels.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/config/ProductUiLabels.xml?rev=1094121&r1=1094120&r2=1094121&view=diff ============================================================================== --- ofbiz/trunk/applications/product/config/ProductUiLabels.xml (original) +++ ofbiz/trunk/applications/product/config/ProductUiLabels.xml Sun Apr 17 09:17:21 2011 @@ -3860,6 +3860,10 @@ <value xml:lang="zh">ä¸ä¸ªåºååºæ</value> <value xml:lang="zh_TW">åè²¨å ´æå</value> </property> + <property key="FormFieldTitle_orderDecimalQuantity"> + <value xml:lang="en">Allow order decimal quantity</value> + <value xml:lang="fr">Accepte les commandes à quantité décimale</value> + </property> <property key="FormFieldTitle_orderFlatPrice"> <value xml:lang="de">Auftrag Pauschalpreis</value> <value xml:lang="en">Order Flat Price</value> @@ -17672,6 +17676,10 @@ <value xml:lang="zh">æè è¾å ¥ä¸ä¸ªå®¹å¨æ è¯</value> <value xml:lang="zh_TW">æè è¼¸å ¥ä¸å容å¨ID</value> </property> + <property key="ProductOrderDecimalQuantityExistsToOverride"> + <value xml:lang="en">Allow decimal quantity to order can be define by product</value> + <value xml:lang="fr">La possibilité de commandé une quantité décimal peut être définie par produit</value> + </property> <property key="ProductOrderId"> <value xml:lang="de">Auftrag ID</value> <value xml:lang="en">Order ID</value> Modified: ofbiz/trunk/applications/product/entitydef/entitymodel.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/entitydef/entitymodel.xml?rev=1094121&r1=1094120&r2=1094121&view=diff ============================================================================== --- ofbiz/trunk/applications/product/entitydef/entitymodel.xml (original) +++ ofbiz/trunk/applications/product/entitydef/entitymodel.xml Sun Apr 17 09:17:21 2011 @@ -2729,6 +2729,7 @@ under the License. <field name="lastModifiedByUserLogin" type="id-vlong"></field> <field name="inShippingBox" type="indicator"></field> <field name="defaultShipmentBoxTypeId" type="id"></field> + <field name="orderDecimalQuantity" type="indicator"><description>use to indicate if decimal quantity can be ordered for this product. Default value is Y</description></field> <prim-key field="productId"/> <relation type="one" fk-name="PROD_TYPE" rel-entity-name="ProductType"> <key-map field-name="productTypeId"/> @@ -3755,6 +3756,7 @@ under the License. <field name="addToCartReplaceUpsell" type="indicator"><description>Default N. If Y then on add to cart remove all products in cart with a ProductAssoc record related from the product and with the PRODUCT_UPGRADE type.</description></field> <field name="splitPayPrefPerShpGrp" type="indicator"><description>Default N. If Y then before the order is stored the OrderPaymentPreference record will be split, one for each OrderItemShipGroup.</description></field> <field name="showOutOfStockProducts" type="indicator"><description>Default Y. If N then out of stock products will not be displayed on site</description></field> + <field name="orderDecimalQuantity" type="indicator"><description>use to indicate if decimal quantity can be ordered for this producStore. Default value is Y</description></field> <!-- old fields, deprecated --> <field name="oldStyleSheet" col-name="STYLE_SHEET" type="url"></field> Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductWorker.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductWorker.java?rev=1094121&r1=1094120&r2=1094121&view=diff ============================================================================== --- ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductWorker.java (original) +++ ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductWorker.java Sun Apr 17 09:17:21 2011 @@ -1171,4 +1171,22 @@ nextProd: } } + /** + * worker to test if product can be order with a decimal quantity + * @param delegator : access to DB + * @param poductId : ref. of product + * * @param productStoreId : ref. of store + * @return true if it can be ordered by decimal quantity + * @throws GenericEntityException to catch + */ + public static Boolean isDecimalQuantityOrderAllowed(Delegator delegator, String poductId, String productStoreId) throws GenericEntityException{ + String allowDecimalStore = delegator.findOne("ProductStore", Boolean.TRUE, UtilMisc.toMap("productStoreId", productStoreId)).getString("orderDecimalQuantity"); + String allowDecimalProduct = delegator.findOne("Product", Boolean.TRUE, UtilMisc.toMap("productId", poductId)).getString("orderDecimalQuantity"); + + if("N".equals(allowDecimalProduct) || (UtilValidate.isEmpty(allowDecimalProduct) && "N".equals(allowDecimalStore))){ + return Boolean.FALSE; + } + return Boolean.TRUE; + } + } Modified: ofbiz/trunk/applications/product/widget/catalog/ProductForms.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/widget/catalog/ProductForms.xml?rev=1094121&r1=1094120&r2=1094121&view=diff ============================================================================== --- ofbiz/trunk/applications/product/widget/catalog/ProductForms.xml (original) +++ ofbiz/trunk/applications/product/widget/catalog/ProductForms.xml Sun Apr 17 09:17:21 2011 @@ -257,6 +257,9 @@ under the License. <field use-when="product!=null" position="2" name="createdByText" title="${uiLabelMap.CommonCreatedBy}:"> <display description="[${product.createdByUserLogin}] ${uiLabelMap.CommonOn} ${product.createdDate}" also-hidden="false"/> </field> + <field name="orderDecimalQuantity" > + <drop-down allow-empty="true" ><option key="Y" description="${uiLabelMap.CommonY}"/><option key="N" description="${uiLabelMap.CommonN}"/></drop-down> + </field> <sort-order> <field-group> <sort-field name="productId"/> @@ -322,6 +325,9 @@ under the License. <sort-field name="defaultShipmentBoxTypeId"/> <sort-field name="chargeShipping"/> </field-group> + <field-group title="${uiLabelMap.CommonShoppingCart}" collapsible="true" initially-collapsed="true"> + <sort-field name="orderDecimalQuantity"/> + </field-group> <field-group title="${uiLabelMap.CommonMiscellaneous}" collapsible="true" initially-collapsed="true"> <sort-field name="returnable"/> <sort-field name="includeInPromotions"/> Modified: ofbiz/trunk/applications/product/widget/catalog/ProductStoreForms.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/widget/catalog/ProductStoreForms.xml?rev=1094121&r1=1094120&r2=1094121&view=diff ============================================================================== --- ofbiz/trunk/applications/product/widget/catalog/ProductStoreForms.xml (original) +++ ofbiz/trunk/applications/product/widget/catalog/ProductStoreForms.xml Sun Apr 17 09:17:21 2011 @@ -305,6 +305,9 @@ <field name="reqReturnInventoryReceive"> <drop-down allow-empty="true"><option key="Y" description="${uiLabelMap.CommonY}"/><option key="N" description="${uiLabelMap.CommonN}"/></drop-down> </field> + <field name="orderDecimalQuantity" tooltip="${uiLabelMap.ProductOrderDecimalQuantityExistsToOverride}"> + <drop-down allow-empty="true" ><option key="Y" description="${uiLabelMap.CommonY}"/><option key="N" description="${uiLabelMap.CommonN}"/></drop-down> + </field> <field name="submitButton" title="${uiLabelMap.CommonUpdate}"><submit button-type="button"/></field> <sort-order> <field-group> @@ -336,6 +339,7 @@ <sort-field name="addToCartRemoveIncompat"/> <sort-field name="showCheckoutGiftOptions"/> <sort-field name="prodSearchExcludeVariants"/> + <sort-field name="orderDecimalQuantity"/> </field-group> <field-group title="${uiLabelMap.CommonShipping}" collapsible="true" initially-collapsed="true"> <sort-field name="prorateShipping"/> |
Free forum by Nabble | Edit this page |