events: {
onProcessingChanged: "",
onOrderChanged: "",
- onShipmentChanged: ""
+ onShipmentChanged: "",
+ onUpdateHeader: ""
+ },
+ handlers: {
+ onBarcodeCapture: "captureBarcode"
},
multiSelect: true,
showDeleteAction: 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,
// 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,
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) {
// 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");
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);
// 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,
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;
},
transactItem: function () {
var models = this.selectedModels();
- this.transact(models, true, true);
+ this.transact(models, true);
},
returnItem: function () {
var models = this.selectedModels(),