# HG changeset patch
# User Ranjith S R <ranjith@qualiantech.com>
# Date 1517932186 -19800
#      Tue Feb 06 21:19:46 2018 +0530
# Node ID 7cee1dc2f0d8bcf413734719ab59f49aecae822f
# Parent  1af551f68ec292998c4ad10ed6ff0983f4929add
Related to issue 37840 : Fixed discount calculation roundoff problems

diff -r 1af551f68ec2 -r 7cee1dc2f0d8 src/org/openbravo/retail/discounts/bypaymentmethod/PaymentMethodDiscount.java
--- a/src/org/openbravo/retail/discounts/bypaymentmethod/PaymentMethodDiscount.java	Wed Jan 10 09:53:58 2018 +0100
+++ b/src/org/openbravo/retail/discounts/bypaymentmethod/PaymentMethodDiscount.java	Tue Feb 06 21:19:46 2018 +0530
@@ -43,7 +43,8 @@
     hqlQueries.add("select" + paymentMethodDiscountProperties.getHqlSelect()
         + " from OBDISX_offer_paymentmethod pmd "
         + " where pmd.$naturalOrgCriteria and pmd.$readableSimpleClientCriteria "
-        + " and pmd.$incrementalUpdateCriteria");
+        + " and (pmd.$incrementalUpdateCriteria or "
+        + " pmd.promotionDiscount.$incrementalUpdateCriteria)");
     return hqlQueries;
   }
 
diff -r 1af551f68ec2 -r 7cee1dc2f0d8 web/org.openbravo.retail.discounts.bypaymentmethod/js/paymentmethod-discount.js
--- a/web/org.openbravo.retail.discounts.bypaymentmethod/js/paymentmethod-discount.js	Wed Jan 10 09:53:58 2018 +0100
+++ b/web/org.openbravo.retail.discounts.bypaymentmethod/js/paymentmethod-discount.js	Tue Feb 06 21:19:46 2018 +0530
@@ -1,6 +1,6 @@
 /*
  ************************************************************************************
- * Copyright (C) 2012-2017 Openbravo S.L.U.
+ * Copyright (C) 2012-2018 Openbravo S.L.U.
  * Licensed under the Openbravo Commercial License version 1.0
  * You may obtain a copy of the License at http://www.openbravo.com/legal/obcl.html
  * or in the legal folder of this module distribution.
@@ -128,7 +128,7 @@
               }
 
               // Calculate Discount
-              receiptTotalDiscountToApply = OB.DEC.div(paymentAmtToCalculate, OB.DEC.sub(1, OB.DEC.div(discountRule.discount, 100)));
+              receiptTotalDiscountToApply = OB.DEC.div(OB.DEC.mul(paymentAmtToCalculate, 100), OB.DEC.sub(100, discountRule.discount));
               receiptTotalDiscountToApply = (receiptTotalDiscountToApply > receiptGrossAmtPerDiscount) ? receiptGrossAmtPerDiscount : receiptTotalDiscountToApply;
               receiptTotalDiscountToApply = OB.DEC.div(OB.DEC.mul(receiptTotalDiscountToApply, discountRule.discount), 100);
 
