Fixes issue 41955: Calculate discount value homogeneously on different callouts
authorMark Molina <>
Thu, 10 Oct 2019 22:20:19 -0300
changeset 36621 fc810b87d8a0
parent 36620 4c494b46c371
child 36622 bde2c9c59217
Fixes issue 41955: Calculate discount value homogeneously on different callouts

When creating a purchase order line, the discount value was calculated incorrectly,
so the unit price was charged with a different value than the value wich it was defined
in the purchase price list.

In the Purchase/Sales Order window, when the Product is selected, the prices are loaded
from the header's pricelist. When these prices are loaded the Discount field is calculated
and the field is updated with values returned by the SL_Order_Product callout.

Due to the Discount updation, the SL_Order_Amt callout is also called and it tries to recalculate
the prices again, but in this case it was doing the discount calculation in a different
way than the SL_Order_Product callout and the inverse operation makes an incorrect calculation
of the prices and discounts, and get differences because rounding.

To fix this issue, the discount calculation is made in the same way in all the evolved
callouts. In this case, the SL_Order_Amt callout was updated to get the discounts in the
same way than the SL_Order_Product callout.
--- a/src/org/openbravo/erpCommon/ad_callouts/	Mon Oct 07 19:48:59 2019 -0300
+++ b/src/org/openbravo/erpCommon/ad_callouts/	Thu Oct 10 22:20:19 2019 -0300
@@ -231,8 +231,9 @@
       BigDecimal unitPrice = isTaxIncludedPriceList ? grossBaseUnitPrice : priceStd;
       BigDecimal discount = priceList.compareTo(BigDecimal.ZERO) == 0 || !calcDiscount
           ? BigDecimal.ZERO
-          : priceList.subtract(unitPrice).divide(priceList, stdPrecision, RoundingMode.HALF_EVEN)
-              .multiply(new BigDecimal("100")).setScale(stdPrecision, RoundingMode.HALF_EVEN);
+          : priceList.subtract(unitPrice)
+              .multiply(new BigDecimal("100"))
+              .divide(priceList, stdPrecision, RoundingMode.HALF_UP);
       log4j.debug("Discount rounded: " + discount.toString());
       info.addResult("inpdiscount", discount);