details:   https://code.openbravo.com/erp/devel/pi/rev/e367e4ce1f98
changeset: 22884:e367e4ce1f98
user:      Atul Gaware <atul.gaware <at> openbravo.com>
date:      Tue Apr 15 16:11:19 2014 +0530
summary:   Fixes Issue 24569 Inconsistent Discount when using "Discounts and 
Promotions"

diffstat:

 src/org/openbravo/erpCommon/ad_callouts/SL_Order_Amt.java |  28 +++++++++++++-
 1 files changed, 26 insertions(+), 2 deletions(-)

diffs (73 lines):

diff -r 426835c75f78 -r e367e4ce1f98 
src/org/openbravo/erpCommon/ad_callouts/SL_Order_Amt.java
--- a/src/org/openbravo/erpCommon/ad_callouts/SL_Order_Amt.java Wed Apr 16 
14:54:15 2014 +0530
+++ b/src/org/openbravo/erpCommon/ad_callouts/SL_Order_Amt.java Tue Apr 15 
16:11:19 2014 +0530
@@ -113,6 +113,7 @@
     PriceList currentPriceList = OBDal.getInstance().get(PriceList.class, 
data[0].mPricelistId);
     boolean isTaxIncludedPriceList = currentPriceList.isPriceIncludesTax();
     boolean isGrossUnitPriceChanged = strChanged.equals("inpgrossUnitPrice");
+    boolean calcDiscount = true;
     boolean forceSetPriceStd = false;
     if (data1 != null && data1.length > 0) {
       strStockSecurity = data1[0].stock;
@@ -220,6 +221,17 @@
       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) {
+          calcDiscount = false;
+        } else {
+          calcDiscount = true;
+        }
       } else {
         priceStd = priceActual;
       }
@@ -259,7 +271,6 @@
           pricePrecision, taxBaseAmt, qtyOrdered);
 
       priceActual = netUnitPrice;
-
       if (cancelPriceAd) {
         grossBaseUnitPrice = grossUnitPrice;
         priceStd = netUnitPrice;
@@ -270,6 +281,18 @@
             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) {
+          calcDiscount = false;
+        } else {
+          calcDiscount = true;
+        }
+
       }
 
       resultado.append("new Array(\"inpgrosspricestd\", " + 
grossBaseUnitPrice.toString() + "),");
@@ -295,7 +318,7 @@
         priceList = netPriceList;
         unitPrice = priceStd;
       }
-      if (priceList.compareTo(BigDecimal.ZERO) == 0) {
+      if (priceList.compareTo(BigDecimal.ZERO) == 0 || !calcDiscount) {
         discount = ZERO;
       } else {
         log4j.debug("pricelist:" + priceList.toString());
@@ -303,6 +326,7 @@
         discount = priceList.subtract(unitPrice).multiply(new 
BigDecimal("100"))
             .divide(priceList, stdPrecision, BigDecimal.ROUND_HALF_EVEN);
       }
+
       log4j.debug("Discount rounded: " + discount.toString());
       resultado.append("new Array(\"inpdiscount\", " + discount.toString() + 
"),");
 

------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/NeoTech
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to