# HG changeset patch
# User Ranjith S R <ranjith@qualiantech.com>
# Date 1462189274 -19800
#      Mon May 02 17:11:14 2016 +0530
# Node ID dcbf34334b912565202ed9e6ea40cd9657104652
# Parent  ebcf847889156583ce47314bb5cb5713d8551563
Fixes issue 32822 : Removed multi receipt line selection event

Added condition to display Toolbar buttons(+, -, quantity) on receipt line selection events

diff -r ebcf84788915 -r dcbf34334b91 web/org.openbravo.retail.posterminal/js/components/renderorderline.js
--- a/web/org.openbravo.retail.posterminal/js/components/renderorderline.js	Thu Apr 28 20:15:06 2016 +0200
+++ b/web/org.openbravo.retail.posterminal/js/components/renderorderline.js	Mon May 02 17:11:14 2016 +0530
@@ -25,9 +25,6 @@
     }
     this.model.trigger('selected', this.model);
     this.model.trigger('click', this.model);
-    this.bubble('onReceiptLineSelected', {
-      product: this.model.get('product')
-    });
   },
   events: {
     onLineChecked: ''
diff -r ebcf84788915 -r dcbf34334b91 web/org.openbravo.retail.posterminal/js/pointofsale/view/editline.js
--- a/web/org.openbravo.retail.posterminal/js/pointofsale/view/editline.js	Thu Apr 28 20:15:06 2016 +0200
+++ b/web/org.openbravo.retail.posterminal/js/pointofsale/view/editline.js	Mon May 02 17:11:14 2016 +0530
@@ -1,6 +1,6 @@
 /*
  ************************************************************************************
- * Copyright (C) 2012-2015 Openbravo S.L.U.
+ * Copyright (C) 2012-2016 Openbravo S.L.U.
  * Licensed under the Openbravo Commercial License version 1.0
  * You may obtain a copy of the License at http://www.openbravo.com/legal/obcl.html
  * or in the legal folder of this module distribution.
@@ -494,7 +494,8 @@
     onEditLine: '',
     onReturnLine: '',
     onShowPopup: '',
-    onShowMultiSelection: ''
+    onShowMultiSelection: '',
+    onReceiptLineSelected: ''
   },
   handlers: {
     onCheckBoxBehaviorForTicketLine: 'checkBoxBehavior',
@@ -540,11 +541,7 @@
     } else {
       //The fix for issue 31509 adds a selected callback after 'off'ing the callbacks but before
       //restoring them. We need to ensure that both callback objects are merged
-      this.receipt.get('lines')._callbacks.selected.tail.next = this.selectedCallbacks.next.next;
-      this.receipt.get('lines')._callbacks.selected.tail.context = this.selectedCallbacks.next.context;
-      this.receipt.get('lines')._callbacks.selected.tail.callback = this.selectedCallbacks.next.callback;
-      this.receipt.get('lines')._callbacks.selected.tail = this.selectedCallbacks.tail;
-
+      this.receipt.get('lines')._callbacks.selected = this.selectedCallbacks;
       this.receipt.get('lines')._callbacks.click = this.clickCallbacks;
       if (this.receipt.get('lines').length > 0) {
         var line = this.selectedLine;
@@ -774,10 +771,16 @@
   },
   receiptChanged: function () {
     this.inherited(arguments);
-
     this.line = null;
-
-    this.receipt.get('lines').on('selected', this.selectedListener, this);
+    var me = this;
+    this.receipt.get('lines').on('selected', function (lineSelected) {
+      if (lineSelected) {
+        me.selectedListener(lineSelected);
+        me.doReceiptLineSelected({
+          product: lineSelected.get('product')
+        });
+      }
+    }, this);
   },
 
   render: function () {
diff -r ebcf84788915 -r dcbf34334b91 web/org.openbravo.retail.posterminal/js/pointofsale/view/keyboardorder.js
--- a/web/org.openbravo.retail.posterminal/js/pointofsale/view/keyboardorder.js	Thu Apr 28 20:15:06 2016 +0200
+++ b/web/org.openbravo.retail.posterminal/js/pointofsale/view/keyboardorder.js	Mon May 02 17:11:14 2016 +0530
@@ -44,12 +44,6 @@
         }
       }
     }
-    this.$.minusBtn.waterfall('onDisableButton', {
-      disabled: !this.selectedModelsSameQty
-    });
-    this.$.plusBtn.waterfall('onDisableButton', {
-      disabled: !this.selectedModelsSameQty
-    });
   },
   keyboardOnDiscountsMode: function (inSender, inEvent) {
     if (inEvent.status) {
diff -r ebcf84788915 -r dcbf34334b91 web/org.openbravo.retail.posterminal/js/pointofsale/view/pointofsale.js
--- a/web/org.openbravo.retail.posterminal/js/pointofsale/view/pointofsale.js	Thu Apr 28 20:15:06 2016 +0200
+++ b/web/org.openbravo.retail.posterminal/js/pointofsale/view/pointofsale.js	Mon May 02 17:11:14 2016 +0530
@@ -1,6 +1,6 @@
 /*
  ************************************************************************************
- * Copyright (C) 2013-2015 Openbravo S.L.U.
+ * Copyright (C) 2013-2016 Openbravo S.L.U.
  * Licensed under the Openbravo Commercial License version 1.0
  * You may obtain a copy of the License at http://www.openbravo.com/legal/obcl.html
  * or in the legal folder of this module distribution.
@@ -1189,29 +1189,37 @@
     this.waterfall('onChangePricelist', inEvent);
   },
   receiptLineSelected: function (inSender, inEvent) {
-    if (inEvent.product.get('groupProduct') && inEvent.product.get('productType') !== 'S' && !inEvent.product.get('isLinkedToProduct')) {
-      // The line selected is a grouped product, so enable the quantity button
-      this.waterfall('onEnableQtyButton', {
-        enable: true
-      });
-      this.waterfall('onEnablePlusButton', {
-        enable: true
-      });
-      this.waterfall('onEnableMinusButton', {
-        enable: true
-      });
+    var enableButton = true,
+        selectedLines = this.$.multiColumn.$.rightPanel.$.keyboard.selectedModels,
+        selectedLinesSameQty = this.$.multiColumn.$.rightPanel.$.keyboard.selectedModelsSameQty,
+        selectedLinesLength = this.$.multiColumn.$.rightPanel.$.keyboard.selectedModels.length,
+        product, i;
+    if (selectedLinesLength > 1) {
+      for (i = 0; i < selectedLinesLength; i++) {
+        product = selectedLines[i].get('product');
+        if (!product.get('groupProduct') || (product.get('productType') === 'S' && product.get('isLinkedToProduct')) || selectedLines[i].get('originalOrderLineId')) {
+          enableButton = false;
+          break;
+        }
+      }
+      if (enableButton && !selectedLinesSameQty) {
+        enableButton = false;
+      }
     } else {
-      // The line selected is not a grouped product, so disable the quantity button
-      this.waterfall('onEnableQtyButton', {
-        enable: false
-      });
-      this.waterfall('onEnablePlusButton', {
-        enable: false
-      });
-      this.waterfall('onEnableMinusButton', {
-        enable: false
-      });
+      product = selectedLines[0].get('product');
+      if (!product.get('groupProduct') || (product.get('productType') === 'S' && product.get('isLinkedToProduct')) || selectedLines[0].get('originalOrderLineId')) {
+        enableButton = false;
+      }
     }
+    this.waterfall('onEnableQtyButton', {
+      enable: enableButton
+    });
+    this.waterfall('onEnablePlusButton', {
+      enable: enableButton
+    });
+    this.waterfall('onEnableMinusButton', {
+      enable: enableButton
+    });
     OB.UTIL.HookManager.executeHooks('OBPOS_LineSelected', {
       product: inEvent.product,
       context: this
diff -r ebcf84788915 -r dcbf34334b91 web/org.openbravo.retail.posterminal/js/pointofsale/view/toolbar-right.js
--- a/web/org.openbravo.retail.posterminal/js/pointofsale/view/toolbar-right.js	Thu Apr 28 20:15:06 2016 +0200
+++ b/web/org.openbravo.retail.posterminal/js/pointofsale/view/toolbar-right.js	Mon May 02 17:11:14 2016 +0530
@@ -1,6 +1,6 @@
 /*
  ************************************************************************************
- * Copyright (C) 2012-2015 Openbravo S.L.U.
+ * Copyright (C) 2012-2016 Openbravo S.L.U.
  * Licensed under the Openbravo Commercial License version 1.0
  * You may obtain a copy of the License at http://www.openbravo.com/legal/obcl.html
  * or in the legal folder of this module distribution.
@@ -398,6 +398,9 @@
   },
   init: function (model) {
     this.model = model;
+    this.model.get('order').get('lines').on('selected', function (lineSelected) {
+      this.currentLine = lineSelected;
+    }, this);
     //    var me = this;
     //    this.model.get('multiOrders').on('change:isMultiOrders', function (model) {
     //      me.doRightToolbarDisabled({
@@ -419,10 +422,6 @@
     });
   },
   tap: function (options) {
-    this.model.get('order').get('lines').on('selected', function (lineSelected) {
-      this.currentLine = lineSelected;
-    }, this);
-
     if (OB.MobileApp.model.get('serviceSearchMode')) {
       this.$.lbl.setContent(OB.I18N.getLabel('OBPOS_LblEdit'));
       this.doEnableUserInterface();
