# HG changeset patch
# User Rafael Queralta <rafaelcuba81@gmail.com>
# Date 1553796706 14400
#      Thu Mar 28 14:11:46 2019 -0400
# Node ID c7468199be0abac316d0ea68cec869a3457fdfb5
# Parent  ac2f83b3ddfae15ee9276c17bc5cf80ffd80d79d
Fixed issue 40262: Preference "Do not allow Sales with return" does not work
properly. The POS gets blocked after doing a Verified Return

- Seted addProcess to "{}" value and finish "addProduct" process controler to
avoid the WEB Pos get blocked after doing a Verified Return

diff --git a/web/org.openbravo.retail.posterminal/js/model/order.js b/web/org.openbravo.retail.posterminal/js/model/order.js
--- a/web/org.openbravo.retail.posterminal/js/model/order.js
+++ b/web/org.openbravo.retail.posterminal/js/model/order.js
@@ -2641,8 +2641,11 @@
         }
         if (me.isCalculateReceiptLocked === true || !line) {
           OB.error('Save ignored before execute OBPOS_PostAddProductToOrder hook, system has detected that a line is being added when calculate receipt is closed. Ignore line creation');
-          if (attrs && attrs.obposEpccode) {
-            OB.UTIL.RfidController.removeEpc(attrs.obposEpccode);
+          if (attrs) {
+            if (attrs.obposEpccode) {
+              OB.UTIL.RfidController.removeEpc(attrs.obposEpccode);
+            }
+            attrs.cancelOperation = true;
           }
           return null;
         }
@@ -2948,7 +2951,7 @@
       }
     },
 
-    addProductToOrder: function (p, qty, options, attrs, callback) {
+    addProductToOrder: function (p, qty, options, attrs, callback, execution) {
       var executeAddProduct, finalCallback, me = this,
           attributeSearchAllowed = OB.MobileApp.model.hasPermission('OBPOS_EnableSupportForProductAttributes', true);
       finalCallback = function (success, orderline) {
@@ -3043,6 +3046,9 @@
               }
             }
             executeAddProduct();
+            if (!OB.UTIL.isNullOrUndefined(args.attrs) && args.attrs.cancelOperation) {
+              OB.UTIL.ProcessController.finish('addProduct', execution);
+            }
           });
         } else {
           executeAddProduct();
@@ -3854,6 +3860,9 @@
         }
         if (qty > 0 && negativeLines > 0) {
           OB.UTIL.showError(OB.I18N.getLabel('OBPOS_MsgCannotAddPositive'));
+          if (!OB.UTIL.isNullOrUndefined(OB.MobileApp.model.receipt.addProcess)) {
+            OB.MobileApp.model.receipt.addProcess = {};
+          }
           return true;
         } else if (qty < 0 && negativeLines !== receiptLines) {
           OB.UTIL.showError(OB.I18N.getLabel('OBPOS_MsgCannotAddNegative'));
