# HG changeset patch
# User Ranjith S R <ranjith@qualiantech.com>
# Date 1549353825 -19800
#      Tue Feb 05 13:33:45 2019 +0530
# Node ID 54faf346af7083b97d21e6d816d1742968dc462c
# Parent  b6f152a1ed2b0613fa2cb122eb656eabc8fb9872
Related to issue 40007 : Discount Should be calculated from discount models which are not hidden

* If qtyOffer is ZERO, for Discount calculation line qty must be used

diff -r b6f152a1ed2b -r 54faf346af70 web/org.openbravo.retail.discounts.discountmatrixmanagement/js/hookRoleDiscounts.js
--- a/web/org.openbravo.retail.discounts.discountmatrixmanagement/js/hookRoleDiscounts.js	Tue Feb 05 13:31:35 2019 +0530
+++ b/web/org.openbravo.retail.discounts.discountmatrixmanagement/js/hookRoleDiscounts.js	Tue Feb 05 13:33:45 2019 +0530
@@ -117,7 +117,12 @@
             if (promotion.percentage !== undefined) {
               discountAmount += actualPrice * promotion.percentage / 100;
             } else {
-              discountAmount += OB.DEC.div(promotion.amt, promotion.qtyOffer);
+              if (!promotion.qtyOffer && promotion.qtyOffer === 0) {
+                promotion.qtyOffer = line.get('qty');
+              }
+              if (!promotion.hidden) {
+                discountAmount += OB.DEC.div(promotion.amt, promotion.qtyOffer);
+              }
             }
             if (OB.Model.Discounts.discountRules[promotion.discountType].isManual) {
               checkDiscount = true;
