# HG changeset patch
# User Ranjith S R <ranjith@qualiantech.com>
# Date 1465197533 -19800
#      Mon Jun 06 12:48:53 2016 +0530
# Node ID eaec01ee449dd145e5d4621759f28c6ff0c2ad3f
# Parent  c9b5a4ff8a4ff76ae411df1bd75787ba15cadf27
Fixes issue 31877 : Replacing remaining qty with return quantity

- backout changeset : ca558e1f022d
- Replaced OB Error with Popup Msg

diff -r c9b5a4ff8a4f -r eaec01ee449d web/org.openbravo.retail.returns/js/modalReturnLines.js
--- a/web/org.openbravo.retail.returns/js/modalReturnLines.js	Mon Jun 06 11:13:14 2016 +0530
+++ b/web/org.openbravo.retail.returns/js/modalReturnLines.js	Mon Jun 06 12:48:53 2016 +0530
@@ -102,7 +102,8 @@
       onApplyChange: 'applyChange'
     },
     events: {
-      onCorrectQty: ''
+      onCorrectQty: '',
+      onShowPopup: ''
     },
     isGiftCard: false,
     applyChange: function (inSender, inEvent) {
@@ -113,7 +114,6 @@
       if (index !== -1) {
         if (this.$.checkboxButtonReturn.checked) {
           var initialQty = inEvent.lines[index].quantity;
-          inEvent.lines[index].remainingQuantity = this.$.quantity.getValue();
           var qty = this.$.quantity.getValue();
           var orderList = OB.MobileApp.model.orderList;
           enyo.forEach(orderList.models, function (order) {
@@ -125,11 +125,18 @@
               }
             });
           });
-          if (qty > inEvent.lines[index].quantity) {
-            OB.UTIL.showWarning(OB.I18N.getLabel('OBRETUR_ExceedsQuantity') + ' ' + me.newAttribute.name);
+          if (qty > inEvent.lines[index].remainingQuantity) {
+            me.doShowPopup({
+              popup: 'OB_UI_MessageDialog',
+              args: {
+                message: (OB.I18N.getLabel('OBRETUR_ExceedsQuantity') + ' ' + me.newAttribute.name)
+              }
+            });
             if (!inEvent.duplicateLine) {
               inEvent.lines.splice(index, 1);
             }
+          } else {
+            inEvent.lines[index].returnQuantity = this.$.quantity.getValue();
           }
           // update promotions amount to the quantity returned
           enyo.forEach(this.newAttribute.promotions, function (p) {
@@ -453,7 +460,7 @@
                   _.each(me.args.args.order.receiptLines, function (line) {
                     var createLineFunction = function (prod) {
                         var order = me.args.args.context.model.get('order');
-                        var qty = line.remainingQuantity;
+                        var qty = line.returnQuantity;
                         if (order.get('orderType') !== 1) {
                           qty = qty ? -qty : -1;
                         }
