From 7f5a410b7ed6b92ef045cece8bd05af5c3573338 Mon Sep 17 00:00:00 2001
From: Prakash M <prakash@qualiantech.com>
Date: Thu, 17 Dec 2020 21:18:37 +0530
Subject: [PATCH] Fixed BUG-45589: Fixes process timeout when error raised in
 addProduct * Added callback with success as false to handle process
 completion

---
 .../js/model/order.js                         | 41 +++++++++++++++----
 1 file changed, 34 insertions(+), 7 deletions(-)

diff --git a/web/org.openbravo.retail.posterminal/js/model/order.js b/web/org.openbravo.retail.posterminal/js/model/order.js
index f0976ef88..728762db7 100644
--- a/web/org.openbravo.retail.posterminal/js/model/order.js
+++ b/web/org.openbravo.retail.posterminal/js/model/order.js
@@ -3505,6 +3505,9 @@
               }
               attrs.cancelOperation = true;
             }
+            if (callback) {
+              callback(false, null);
+            }
             return null;
           }
 
@@ -3580,7 +3583,8 @@
                 p,
                 options.isVerifiedReturn ? -data.result : data.result,
                 options,
-                attrs
+                attrs,
+                callback
               );
               execPostAddProductToOrderHook();
             }
@@ -3614,6 +3618,9 @@
               if (attrs && attrs.obposEpccode) {
                 OB.UTIL.RfidController.removeEpc(attrs.obposEpccode);
               }
+              if (callback) {
+                callback(false, null);
+              }
               return null;
             }
             checkLineStock(function() {
@@ -3630,6 +3637,9 @@
                 },
                 function(args) {
                   if (args && args.cancelOperation) {
+                    if (callback) {
+                      callback(false, null);
+                    }
                     return;
                   }
                   if (args.receipt.isCalculateReceiptLocked === true) {
@@ -3639,6 +3649,9 @@
                     if (args && args.attrs && args.attrs.obposEpccode) {
                       OB.UTIL.RfidController.removeEpc(args.attrs.obposEpccode);
                     }
+                    if (callback) {
+                      callback(false, null);
+                    }
                     return null;
                   }
                   if (OB.MobileApp.model.get('inPaymentTab')) {
@@ -3652,6 +3665,9 @@
                           args.attrs.obposEpccode
                         );
                       }
+                      if (callback) {
+                        callback(false, null);
+                      }
                       return;
                     }
                   }
@@ -3714,14 +3730,16 @@
                         args.p,
                         args.attrs.relatedLines[0].qty,
                         args.options,
-                        args.attrs
+                        args.attrs,
+                        callback
                       );
                     } else {
                       line = args.receipt.createLine(
                         args.p,
                         args.qty,
                         args.options,
-                        args.attrs
+                        args.attrs,
+                        callback
                       );
                     }
                   }
@@ -3739,6 +3757,9 @@
                 if (attrs && attrs.obposEpccode) {
                   OB.UTIL.RfidController.removeEpc(attrs.obposEpccode);
                 }
+                if (callback) {
+                  callback(false, null);
+                }
                 return;
               }
             }
@@ -3750,6 +3771,9 @@
               if (attrs && attrs.obposEpccode) {
                 OB.UTIL.RfidController.removeEpc(attrs.obposEpccode);
               }
+              if (callback) {
+                callback(false, null);
+              }
               return null;
             }
             checkLineStock(function() {
@@ -3761,15 +3785,15 @@
                 newLine = false;
               } else {
                 if (p.get('avoidSplitProduct')) {
-                  line = me.createLine(p, qty, options, attrs);
+                  line = me.createLine(p, qty, options, attrs, callback);
                 } else {
                   if (qty >= 0) {
                     for (count = 0; count < qty; count++) {
-                      line = me.createLine(p, 1, options, attrs);
+                      line = me.createLine(p, 1, options, attrs, callback);
                     }
                   } else {
                     for (count = 0; count > qty; count--) {
-                      line = me.createLine(p, -1, options, attrs);
+                      line = me.createLine(p, -1, options, attrs, callback);
                     }
                   }
                 }
@@ -4888,7 +4912,7 @@
     },
 
     //Attrs is an object of attributes that will be set in order line
-    createLine: function(p, units, options, attrs) {
+    createLine: function(p, units, options, attrs, callback) {
       var me = this,
         orgId,
         orgName;
@@ -4992,6 +5016,9 @@
           if (attrs && attrs.obposEpccode) {
             OB.UTIL.RfidController.removeEpc(attrs.obposEpccode);
           }
+          if (callback) {
+            callback(false, null);
+          }
           return null;
         }
 
-- 
2.20.1

