From 5e750069705a3c46b7c988621b6f8be9b19335b1 Mon Sep 17 00:00:00 2001
From: Prakash M <prakash@qualiantech.com>
Date: Thu, 17 Dec 2020 21:56:21 +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 4ee063863..7397e958c 100644
--- a/web/org.openbravo.retail.posterminal/js/model/order.js
+++ b/web/org.openbravo.retail.posterminal/js/model/order.js
@@ -3501,6 +3501,9 @@
               }
               attrs.cancelOperation = true;
             }
+            if (callback) {
+              callback(false, null);
+            }
             return null;
           }
 
@@ -3579,7 +3582,8 @@
                   ? -data.result
                   : data.result,
                 options,
-                attrs
+                attrs,
+                callback
               );
               execPostAddProductToOrderHook();
             }
@@ -3617,6 +3621,9 @@
               ) {
                 OB.UTIL.RfidController.removeEpc(attrs.obposEpccode);
               }
+              if (callback) {
+                callback(false, null);
+              }
               return null;
             }
             checkLineStock(function() {
@@ -3633,6 +3640,9 @@
                 },
                 function(args) {
                   if (args && args.cancelOperation) {
+                    if (callback) {
+                      callback(false, null);
+                    }
                     return;
                   }
                   if (args.receipt.isCalculateReceiptLocked === true) {
@@ -3647,6 +3657,9 @@
                     ) {
                       OB.UTIL.RfidController.removeEpc(args.attrs.obposEpccode);
                     }
+                    if (callback) {
+                      callback(false, null);
+                    }
                     return null;
                   }
                   if (OB.MobileApp.model.get('inPaymentTab')) {
@@ -3665,6 +3678,9 @@
                           args.attrs.obposEpccode
                         );
                       }
+                      if (callback) {
+                        callback(false, null);
+                      }
                       return;
                     }
                   }
@@ -3727,14 +3743,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
                       );
                     }
                   }
@@ -3756,6 +3774,9 @@
                 ) {
                   OB.UTIL.RfidController.removeEpc(attrs.obposEpccode);
                 }
+                if (callback) {
+                  callback(false, null);
+                }
                 return;
               }
             }
@@ -3771,6 +3792,9 @@
               ) {
                 OB.UTIL.RfidController.removeEpc(attrs.obposEpccode);
               }
+              if (callback) {
+                callback(false, null);
+              }
               return null;
             }
             checkLineStock(function() {
@@ -3782,15 +3806,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);
                     }
                   }
                 }
@@ -4941,7 +4965,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;
@@ -5049,6 +5073,9 @@
           ) {
             OB.UTIL.RfidController.removeEpc(attrs.obposEpccode);
           }
+          if (callback) {
+            callback(false, null);
+          }
           return null;
         }
 
-- 
2.20.1

