details:   https://code.openbravo.com/erp/devel/pi/rev/1d09b6a639cf
changeset: 35527:1d09b6a639cf
user:      Mark Molina <mark.molina <at> doceleguas.com>
date:      Wed Feb 27 18:43:27 2019 -0300
summary:   Fixes issue 40275: Error when calculating the field "amount" discount

The discount was wrongly calculated because an incorrect rounding on its 
calculation.
When discounts are applied the ActualPrice is calculated from the standard 
price and rounded.
When the reverse process is made (calculate the Price Std from the Actual 
Price) could be
differences because the rounding previously done to the ActualPrice.
To avoid those differences first is divided by the price list and rounded and 
then multiplied
by 100 and rounded again when the discount is calculated.

diffstat:

 src/org/openbravo/erpCommon/ad_callouts/SL_Order_Amt.java |  7 +++----
 1 files changed, 3 insertions(+), 4 deletions(-)

diffs (24 lines):

diff -r b26d445bb8b1 -r 1d09b6a639cf 
src/org/openbravo/erpCommon/ad_callouts/SL_Order_Amt.java
--- a/src/org/openbravo/erpCommon/ad_callouts/SL_Order_Amt.java Mon Mar 11 
14:52:04 2019 +0100
+++ b/src/org/openbravo/erpCommon/ad_callouts/SL_Order_Amt.java Wed Feb 27 
18:43:27 2019 -0300
@@ -11,7 +11,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2001-2017 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2019 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -231,9 +231,8 @@
       BigDecimal unitPrice = isTaxIncludedPriceList ? grossBaseUnitPrice : 
priceStd;
       BigDecimal discount = priceList.compareTo(BigDecimal.ZERO) == 0 || 
!calcDiscount
           ? BigDecimal.ZERO
-          : priceList.subtract(unitPrice)
-              .multiply(new BigDecimal("100"))
-              .divide(priceList, stdPrecision, RoundingMode.HALF_EVEN);
+          : priceList.subtract(unitPrice).divide(priceList, stdPrecision, 
RoundingMode.HALF_EVEN)
+              .multiply(new BigDecimal("100")).setScale(stdPrecision, 
RoundingMode.HALF_EVEN);
       log4j.debug("Discount rounded: " + discount.toString());
       info.addResult("inpdiscount", discount);
 


_______________________________________________
Openbravo-commits mailing list
Openbravo-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to