From 28313973eb67befe92bbe36a6f7fa5bd88ec7dc6 Mon Sep 17 00:00:00 2001
From: Prakash M <prakash@qualiantech.com>
Date: Thu, 17 Dec 2020 20:39:47 +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 57296a663..646438147 100644
--- a/web/org.openbravo.retail.posterminal/js/model/order.js
+++ b/web/org.openbravo.retail.posterminal/js/model/order.js
@@ -3396,6 +3396,9 @@
               }
               attrs.cancelOperation = true;
             }
+            if (callback) {
+              callback(false, null);
+            }
             return null;
           }
           OB.UTIL.HookManager.executeHooks(
@@ -3468,7 +3471,8 @@
                 p,
                 options.isVerifiedReturn ? -data.result : data.result,
                 options,
-                attrs
+                attrs,
+                callback
               );
               execPostAddProductToOrderHook();
             }
@@ -3502,6 +3506,9 @@
               if (attrs && attrs.obposEpccode) {
                 OB.UTIL.RfidController.removeEpc(attrs.obposEpccode);
               }
+              if (callback) {
+                callback(false, null);
+              }
               return null;
             }
             checkLineStock(function() {
@@ -3518,6 +3525,9 @@
                 },
                 function(args) {
                   if (args && args.cancelOperation) {
+                    if (callback) {
+                      callback(false, null);
+                    }
                     return;
                   }
                   if (args.receipt.isCalculateReceiptLocked === true) {
@@ -3527,6 +3537,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')) {
@@ -3540,6 +3553,9 @@
                           args.attrs.obposEpccode
                         );
                       }
+                      if (callback) {
+                        callback(false, null);
+                      }
                       return;
                     }
                   }
@@ -3602,14 +3618,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
                       );
                     }
                   }
@@ -3627,6 +3645,9 @@
                 if (attrs && attrs.obposEpccode) {
                   OB.UTIL.RfidController.removeEpc(attrs.obposEpccode);
                 }
+                if (callback) {
+                  callback(false, null);
+                }
                 return;
               }
             }
@@ -3638,6 +3659,9 @@
               if (attrs && attrs.obposEpccode) {
                 OB.UTIL.RfidController.removeEpc(attrs.obposEpccode);
               }
+              if (callback) {
+                callback(false, null);
+              }
               return null;
             }
             checkLineStock(function() {
@@ -3649,15 +3673,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);
                     }
                   }
                 }
@@ -4772,7 +4796,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;
@@ -4876,6 +4900,9 @@
           if (attrs && attrs.obposEpccode) {
             OB.UTIL.RfidController.removeEpc(attrs.obposEpccode);
           }
+          if (callback) {
+            callback(false, null);
+          }
           return null;
         }
 
-- 
2.20.1

