Fixes Issue 29171:The sales order is not taking into account the unit price of
authorAtul Gaware <atul.gaware@openbravo.com>
Mon, 16 Mar 2015 00:07:30 +0530
changeset 26186 33329a8720b2
parent 26185 ed413e5f8b7a
child 26187 e4c7b3d0a0ff
Fixes Issue 29171:The sales order is not taking into account the unit price of
the product when is 0

Corner case regression, when ever unit price is set to zero in the price list
src/org/openbravo/erpCommon/ad_callouts/SL_Order_Amt.java
src/org/openbravo/erpCommon/businessUtility/PriceAdjustment.java
--- a/src/org/openbravo/erpCommon/ad_callouts/SL_Order_Amt.java	Mon Mar 16 14:56:47 2015 +0000
+++ b/src/org/openbravo/erpCommon/ad_callouts/SL_Order_Amt.java	Mon Mar 16 00:07:30 2015 +0530
@@ -221,13 +221,8 @@
       log4j.debug("priceActual:" + priceActual.toString());
       if (!cancelPriceAd) {
         priceStd = PriceAdjustment.calculatePriceStd(order, product, qtyOrdered, priceActual);
-        if (PriceAdjustment.calculatePriceActual(
-            order,
-            product,
-            qtyOrdered,
-            (strPriceStd.equals("") ? ZERO : (new BigDecimal(strPriceStd))).setScale(
-                pricePrecision, BigDecimal.ROUND_HALF_UP)).compareTo(ZERO) == 0
-            && priceActual.compareTo(ZERO) == 0) {
+        if (!priceStd.equals(priceActual) && priceStd.compareTo(ZERO) == 0) {
+          // Check whether price adjustment sets priceStd as Zero
           calcDiscount = false;
         } else {
           calcDiscount = true;
@@ -281,18 +276,12 @@
             RoundingMode.HALF_UP);
         priceStd = FinancialUtils.calculateNetFromGross(strTaxId, baseGrossAmount, pricePrecision,
             taxBaseAmt, qtyOrdered);
-        if (PriceAdjustment.calculatePriceActual(
-            order,
-            product,
-            qtyOrdered,
-            (strGrossUnitPrice.equals("") ? ZERO : (new BigDecimal(strGrossUnitPrice))).setScale(
-                pricePrecision, BigDecimal.ROUND_HALF_UP)).compareTo(ZERO) == 0
-            && grossUnitPrice.compareTo(ZERO) == 0) {
+        if (!grossBaseUnitPrice.equals(grossUnitPrice) && grossBaseUnitPrice.compareTo(ZERO) == 0) {
+          // Check whether price adjustment sets grossBaseUnitPrice as Zero
           calcDiscount = false;
         } else {
           calcDiscount = true;
         }
-
       }
 
       resultado.append("new Array(\"inpgrosspricestd\", " + grossBaseUnitPrice.toString() + "),");
--- a/src/org/openbravo/erpCommon/businessUtility/PriceAdjustment.java	Mon Mar 16 14:56:47 2015 +0000
+++ b/src/org/openbravo/erpCommon/businessUtility/PriceAdjustment.java	Mon Mar 16 00:07:30 2015 +0530
@@ -116,9 +116,18 @@
         }
         log.debug("promo: " + promo + "- " + promo.getDiscount());
         if (applyDiscount) {
-          priceStd = priceStd.add(promo.getDiscountAmount()).divide(
-              BigDecimal.ONE.subtract(promo.getDiscount().divide(BigDecimal.valueOf(100),
-                  precision, BigDecimal.ROUND_HALF_UP)), precision, BigDecimal.ROUND_HALF_UP);
+          // Avoids divide by zero error
+          if (BigDecimal.ONE.subtract(
+              promo.getDiscount().divide(BigDecimal.valueOf(100), precision,
+                  BigDecimal.ROUND_HALF_UP)).compareTo(BigDecimal.ZERO) != 0) {
+            priceStd = priceStd.add(promo.getDiscountAmount()).divide(
+                BigDecimal.ONE.subtract(promo.getDiscount().divide(BigDecimal.valueOf(100),
+                    precision, BigDecimal.ROUND_HALF_UP)), precision, BigDecimal.ROUND_HALF_UP);
+          } else {
+            // 100 % Discount in price adjustment results in priceStd = Zero
+            priceStd = BigDecimal.ZERO;
+          }
+
         }
 
       }