# HG changeset patch
# User Ranjith S R <ranjith@qualiantech.com>
# Date 1592573598 -19800
#      Fri Jun 19 19:03:18 2020 +0530
# Node ID cced63a799ccfae735bd6f6ade839cc05057b689
# Parent  a39209bc1d21a12ca385112c9d8d03f2c017cc81
Related to issue-44308: Coupon can be added if subtype is not defined

* If Subtype is not defined for the issuing company, and if user scan the coupon code with Subtype then
  Coupon should be added as payment without Subtype.
  Subtype should not be validated if Subtype is not defined for the issuing company

diff -r a39209bc1d21 -r cced63a799cc web/org.openbravo.retail.chequecadeau/js/chequecadeauutils.js
--- a/web/org.openbravo.retail.chequecadeau/js/chequecadeauutils.js	Wed Jun 17 20:03:35 2020 +0530
+++ b/web/org.openbravo.retail.chequecadeau/js/chequecadeauutils.js	Fri Jun 19 19:03:18 2020 +0530
@@ -104,24 +104,32 @@
 
           //Code for empty subtype is 000000
           if (coupon.obdicoSubtype !== '000000') {
-            const criteria2 = new OB.App.Class.Criteria()
-              .criterion('issuing_company_id', issuingCompany.get('id'))
-              .criterion('code', coupon.obdicoSubtype);
-
+            const criteria2 = new OB.App.Class.Criteria().criterion(
+              'issuing_company_id',
+              issuingCompany.get('id')
+            );
             const data2 = await OB.App.MasterdataModels.SubType.find(
               criteria2.build()
             );
-            if (data2 && data2.length === 1) {
-              const subType = OB.Dal.transform(OB.Model.SubType, data2[0]);
-              successCallback([issuingCompany, subType]);
+            if (data2.length === 0) {
+              successCallback([issuingCompany]);
             } else {
-              errorCallback({
-                onlyOkButton: true,
-                gs1: true,
-                labeli18n: 'CCGS_SubTypeNotFound',
-                message: 'Sub Type code not found for Issuing Company'
+              const subType = data2.find(function(d) {
+                return d.code === coupon.obdicoSubtype;
               });
-              return;
+              if (subType) {
+                successCallback([
+                  issuingCompany,
+                  OB.Dal.transform(OB.Model.SubType, subType)
+                ]);
+              } else {
+                errorCallback({
+                  onlyOkButton: true,
+                  gs1: true,
+                  labeli18n: 'CCGS_SubTypeNotFound',
+                  message: 'Sub Type code not found for Issuing Company'
+                });
+              }
             }
           } else {
             successCallback([issuingCompany]);
