display barcode misfires
[xtuple] / lib / enyo-x / source / views / transaction_list.js
index 7ecc1a7..e371c11 100644 (file)
@@ -24,7 +24,11 @@ trailing:true, white:true, strict:false*/
     events: {
       onProcessingChanged: "",
       onOrderChanged: "",
-      onShipmentChanged: ""
+      onShipmentChanged: "",
+      onUpdateHeader: ""
+    },
+    handlers: {
+      onBarcodeCapture: "captureBarcode"
     },
     multiSelect: true,
     showDeleteAction: false,
@@ -37,13 +41,33 @@ trailing:true, white:true, strict:false*/
       {name: "returnLine", prerequisite: "canReturnItem",
         method: "returnItem", notify: false, isViewMethod: true}
     ],
+    captureBarcode: function (inSender, inEvent) {
+      var models = _.filter(this.value.models, function (model) {
+        // match on upc code or item number
+        return model.getValue("itemSite.item.barcode") === inEvent.data ||
+          model.getValue("itemSite.item.number") === inEvent.data;
+      });
+      if (models.length > 0) {
+        this.transact(models, true, true);
+      } else {
+        inEvent.noItemFound = true;
+      }
+
+      this.doUpdateHeader(inEvent);
+    },
     /**
-        Helper function for transacting `transact` on an array of models
+        Helper function for transacting `transact` on an array of models.
 
         @param {Array} Models
         @param {Boolean} Prompt user for confirmation on every model
+        @param {String} Optional to handle the transaction function name, if not passed
+        it will use the published value. Used by ReturnMaterial's actions.
+        @param {String} Optional to handle the workspace name, if not passed
+        it will use the published value. Used by ReturnMaterial's actions.
+        @param {String} Optional to handle the quantity attr name, if not passed
+        it will use the model.quantityAttribute. Used by ReturnMaterial's actions.
     */
-    transact: function (models, prompt, transactStock) {
+    transact: function (models, prompt, transFunction, transWorkspace, transQty) {
       var that = this,
         i = -1,
         callback,
@@ -52,7 +76,7 @@ trailing:true, white:true, strict:false*/
       // Recursively transact everything we can
       // #refactor see a simpler implementation of this sort of thing
       // using async in inventory's ReturnListItem stomp
-      callback = function (workspace) {
+      callback = function (workspace, transFunction, transWorkspace, transQty) {
         var model,
           options = {},
           toTransact,
@@ -61,9 +85,12 @@ trailing:true, white:true, strict:false*/
           dispOptions = {},
           wsOptions = {},
           wsParams,
-          transModule = that.getTransModule(),
-          transFunction = that.getTransFunction(),
-          transWorkspace = that.getTransWorkspace();
+          transModule = that.getTransModule();
+
+        transFunction = transFunction || that.getTransFunction();
+        transWorkspace = transWorkspace || that.getTransWorkspace();
+
+        that._printModels = [];
 
         // If argument is false, this whole process was cancelled
         if (workspace === false) {
@@ -72,9 +99,14 @@ trailing:true, white:true, strict:false*/
         // If a workspace brought us here, process the information it obtained
         } else if (workspace) {
           model = workspace.getValue();
-          toTransact = model.get(model.quantityAttribute);
+          toTransact = transQty ? model.get(transQty) : model.get(model.quantityAttribute);
           transDate = model.transactionDate;
 
+
+          if (workspace._printAfterPersist) {
+            that._printModels.push(model);
+          }
+
           if (toTransact) {
             if (transFunction === "receipt") {
               wsOptions.freight = model.get("freight");
@@ -97,6 +129,13 @@ trailing:true, white:true, strict:false*/
           if (data[0]) {
             that.doProcessingChanged({isProcessing: true});
             dispOptions.success = function () {
+              _.each(that._printModels, function (printModel) {
+                // XXX eventually replace _auxilliaryInfo with meta, probably
+                printModel.doPrint(printModel._auxilliaryInfo);
+              });
+              that.doProcessingChanged({isProcessing: false});
+            };
+            dispOptions.error = function () {
               that.doProcessingChanged({isProcessing: false});
             };
             transModule.transactItem(data, dispOptions, transFunction);
@@ -107,18 +146,18 @@ trailing:true, white:true, strict:false*/
         // Else if there's something here we can transact, handle it
         } else {
           model = models[i];
-          toTransact = model.get(model.quantityAttribute);
+          toTransact = transQty ? model.get(transQty) : model.get(model.quantityAttribute);
           if (toTransact === null) {
             toTransact = model.get("balance");
           }
           transDate = model.transactionDate;
 
           // See if there's anything to transact here
-          if (toTransact || transactStock) {
+          if (toTransact || prompt) {
 
             // If prompt or distribution detail required,
             // open a workspace to handle it
-            if (prompt || model.undistributed()) {
+            if (prompt || model.undistributed() || model.requiresDetail()) {
               that.doWorkspace({
                 workspace: transWorkspace,
                 id: model.id,
@@ -142,16 +181,16 @@ trailing:true, white:true, strict:false*/
                 options: options
               };
               data.push(params);
-              callback();
+              callback(null, transFunction, transWorkspace, transQty);
             }
 
           // Nothing to transact, move on
           } else {
-            callback();
+            callback(null, transFunction, transWorkspace, transQty);
           }
         }
       };
-      callback();
+      callback(null, transFunction, transWorkspace, transQty);
     },
     transactAll: function () {
       var models = this.getValue().models;
@@ -163,7 +202,7 @@ trailing:true, white:true, strict:false*/
     },
     transactItem: function () {
       var models = this.selectedModels();
-      this.transact(models, true, true);
+      this.transact(models, true);
     },
     returnItem: function () {
       var models = this.selectedModels(),