# HG changeset patch
# User Ranjith S R <ranjith@qualiantech.com>
# Date 1582264384 -19800
#      Fri Feb 21 11:23:04 2020 +0530
# Node ID d0edc3692236044886d89e90efd38a301dbc1bf7
# Parent  5afa22e0d1ee5eafd2a5590bf147621d242e914c
Fixed issue 43283 : Updated Discount Calculation for Characteristics Definition

* If discount is defined with "Only those defined",
  then discount should be applied if any one of the characteristics present

diff -r 5afa22e0d1ee -r d0edc3692236 web/org.openbravo.retail.discounts/js/discountsengine/common/discount-rules.js
--- a/web/org.openbravo.retail.discounts/js/discountsengine/common/discount-rules.js	Mon Dec 02 07:20:55 2019 +0000
+++ b/web/org.openbravo.retail.discounts/js/discountsengine/common/discount-rules.js	Fri Feb 21 11:23:04 2020 +0530
@@ -166,6 +166,7 @@
       if (rule.productCharacteristics.length === 0) {
         applicable = true;
       } else {
+        let lineCount = 0;
         rule.productCharacteristics.forEach(ruleProdChar => {
           if (line.product.productCharacteristics) {
             let found = line.product.productCharacteristics.find(
@@ -178,13 +179,16 @@
             );
             if (!found) {
               elementFound = false;
+            } else {
+              lineCount++;
             }
           } else {
             elementFound = false;
           }
         });
         applicable =
-          (onlyIncluded && elementFound) || (!onlyIncluded && !elementFound);
+          (rule.includedCharacteristics === 'N' && lineCount > 0) ||
+          (rule.includedCharacteristics === 'Y' && !elementFound);
       }
 
       return applicable;
