# HG changeset patch
# User Ranjith S R <ranjith@qualiantech.com>
# Date 1477569064 -19800
#      Thu Oct 27 17:21:04 2016 +0530
# Node ID 4a4b378bc6f66052771ec737eaf4ab1f6aa4a38c
# Parent  b2d89723ef11c0731140c20bcc67e8e7c7408218
Related to issue 34271 : Validating double click for adding product

diff -r b2d89723ef11 -r 4a4b378bc6f6 web/org.openbravo.retail.posterminal/js/model/order.js
--- a/web/org.openbravo.retail.posterminal/js/model/order.js	Thu Oct 27 09:36:07 2016 +0200
+++ b/web/org.openbravo.retail.posterminal/js/model/order.js	Thu Oct 27 17:21:04 2016 +0530
@@ -1518,12 +1518,12 @@
               }
               OB.UTIL.SynchronizationHelper.finished(synchId, 'HasServices');
               if (callback) {
-                callback(true, args.orderline);
+                callback('service', args.orderline);
               }
             }, args.orderline);
           } else {
             if (callback) {
-              callback(true, args.orderline);
+              callback('service', args.orderline);
             }
           }
         });
diff -r b2d89723ef11 -r 4a4b378bc6f6 web/org.openbravo.retail.posterminal/js/pointofsale/view/pointofsale.js
--- a/web/org.openbravo.retail.posterminal/js/pointofsale/view/pointofsale.js	Thu Oct 27 09:36:07 2016 +0200
+++ b/web/org.openbravo.retail.posterminal/js/pointofsale/view/pointofsale.js	Thu Oct 27 17:21:04 2016 +0530
@@ -407,13 +407,17 @@
     });
   },
   addProductToOrder: function (inSender, inEvent) {
-    var targetOrder;
+    var targetOrder, me = this;
     if (inEvent && inEvent.targetOrder) {
       targetOrder = inEvent.targetOrder;
     } else {
       targetOrder = this.model.get('order');
     }
-    if (targetOrder.pendingAddProduct && targetOrder.pendingAddProduct === true) {
+    if (targetOrder.addProcess && targetOrder.addProcess.pending === true) {
+      if (targetOrder.addProcess.product === inEvent.product.get('id')) {
+        targetOrder.addProcess.qtyToAdd += 1;
+        targetOrder.addProcess.inEvent = inEvent;
+      }
       return false;
     }
     if (targetOrder.get('isEditable') === false) {
@@ -513,9 +517,19 @@
         }
         return true;
       }
-      args.receipt.pendingAddProduct = true;
+      args.receipt.addProcess = {};
+      args.receipt.addProcess.pending = true;
+      args.receipt.addProcess.product = args.productToAdd.get('id');
+      args.receipt.addProcess.qtyToAdd = 0;
       args.receipt.addProduct(args.productToAdd, args.qtyToAdd, args.options, args.attrs, function (success, orderline) {
-        args.receipt.pendingAddProduct = false;
+        args.receipt.addProcess.pending = false;
+        if (success === 'service') {
+          if (args.receipt.addProcess.qtyToAdd > 0) {
+            args.receipt.addProcess.inEvent.qty = args.receipt.addProcess.qtyToAdd;
+            me.addProductToOrder(inSender, args.receipt.addProcess.inEvent);
+          }
+          success = true;
+        }
         args.context.model.get('orderList').saveCurrent();
         if (inEvent.callback) {
           inEvent.callback.call(inEvent.context, success, orderline);
