From 7dae05acc596f4ced19736f81dabb0b7a14b41d3 Mon Sep 17 00:00:00 2001 From: Oliver Date: Mon, 4 Apr 2022 16:20:19 +1000 Subject: [PATCH] Fix for scanItemsIntoLocation function - Accept list of objects rather than pk values - Conform to API requirements --- InvenTree/stock/templates/stock/item_base.html | 7 ++++++- InvenTree/templates/js/translated/barcode.js | 16 +++++++--------- InvenTree/templates/js/translated/stock.js | 2 +- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/InvenTree/stock/templates/stock/item_base.html b/InvenTree/stock/templates/stock/item_base.html index 8f62f2c852..dd77d26d1c 100644 --- a/InvenTree/stock/templates/stock/item_base.html +++ b/InvenTree/stock/templates/stock/item_base.html @@ -505,7 +505,12 @@ $("#barcode-unlink").click(function() { }); $("#barcode-scan-into-location").click(function() { - scanItemsIntoLocation([{{ item.id }}]); + + inventreeGet('{% url "api-stock-detail" item.pk %}', {}, { + success: function(item) { + scanItemsIntoLocation([item]); + } + }); }); function itemAdjust(action) { diff --git a/InvenTree/templates/js/translated/barcode.js b/InvenTree/templates/js/translated/barcode.js index 40d143887d..f59f2a3054 100644 --- a/InvenTree/templates/js/translated/barcode.js +++ b/InvenTree/templates/js/translated/barcode.js @@ -545,7 +545,7 @@ function barcodeCheckIn(location_id) { /* * Display dialog to check a single stock item into a stock location */ -function scanItemsIntoLocation(item_id_list, options={}) { +function scanItemsIntoLocation(item_list, options={}) { var modal = options.modal || '#modal-form'; @@ -595,9 +595,10 @@ function scanItemsIntoLocation(item_id_list, options={}) { var items = []; - item_id_list.forEach(function(pk) { + item_list.forEach(function(item) { items.push({ - pk: pk, + pk: item.pk || item.id, + quantity: item.quantity, }); }); @@ -617,13 +618,10 @@ function scanItemsIntoLocation(item_id_list, options={}) { // First hide the modal $(modal).modal('hide'); - if (status == 'success' && 'success' in response) { - addCachedAlert(response.success); - location.reload(); + if (options.success) { + options.success(response); } else { - showMessage('{% trans "Error transferring stock" %}', { - style: 'danger', - }); + location.reload(); } } } diff --git a/InvenTree/templates/js/translated/stock.js b/InvenTree/templates/js/translated/stock.js index ade8bc5a0a..b7afdbca44 100644 --- a/InvenTree/templates/js/translated/stock.js +++ b/InvenTree/templates/js/translated/stock.js @@ -1972,7 +1972,7 @@ function loadStockTable(table, options) { var items = []; selections.forEach(function(item) { - items.push(item.pk); + items.push(item); }); scanItemsIntoLocation(items);