From 2c8e274aa9f8dd48fa9b3a2ed45172e19b07f719 Mon Sep 17 00:00:00 2001 From: Oliver Date: Mon, 4 Apr 2022 14:23:57 +1000 Subject: [PATCH 1/6] Tweaks for barcode scanning functionality - Prevent javascript errors (cherry picked from commit 9129a42a3e2a5c5939e6002d3b4010b3fd9cc20e) --- InvenTree/templates/js/translated/barcode.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/InvenTree/templates/js/translated/barcode.js b/InvenTree/templates/js/translated/barcode.js index 6be56d14f1..40d143887d 100644 --- a/InvenTree/templates/js/translated/barcode.js +++ b/InvenTree/templates/js/translated/barcode.js @@ -366,7 +366,6 @@ function barcodeCheckIn(location_id) { // List of items we are going to checkin var items = []; - function reloadTable() { modalEnable(modal, false); @@ -389,10 +388,17 @@ function barcodeCheckIn(location_id) { `; items.forEach(function(item) { + + var location_info = `${item.location}`; + + if (item.location_detail) { + location_info = `${item.location_detail.name}`; + } + html += ` ${imageHoverIcon(item.part_detail.thumbnail)} ${item.part_detail.name} - ${item.location_detail.name} + ${location_info} ${item.quantity} ${makeIconButton('fa-times-circle icon-red', 'button-item-remove', item.pk, '{% trans "Remove stock item" %}')} `; @@ -469,6 +475,12 @@ function barcodeCheckIn(location_id) { data.items = entries; + // Prevent submission without any entries + if (entries.length == 0) { + showBarcodeMessage(modal, '{% trans "No barcode provided" %}', 'warning'); + return; + } + inventreePut( '{% url "api-stock-transfer" %}', data, From 7dae05acc596f4ced19736f81dabb0b7a14b41d3 Mon Sep 17 00:00:00 2001 From: Oliver Date: Mon, 4 Apr 2022 16:20:19 +1000 Subject: [PATCH 2/6] 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); From 782a0f3576577516008e7a21afcc3243ac8a1344 Mon Sep 17 00:00:00 2001 From: Oliver Date: Mon, 4 Apr 2022 16:23:17 +1000 Subject: [PATCH 3/6] Fix for scanIntoLocation function --- InvenTree/templates/js/translated/barcode.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/InvenTree/templates/js/translated/barcode.js b/InvenTree/templates/js/translated/barcode.js index f59f2a3054..b08d9170bc 100644 --- a/InvenTree/templates/js/translated/barcode.js +++ b/InvenTree/templates/js/translated/barcode.js @@ -359,7 +359,7 @@ function unlinkBarcode(stockitem) { /* * Display dialog to check multiple stock items in to a stock location. */ -function barcodeCheckIn(location_id) { +function barcodeCheckIn(location_id, options={}) { var modal = '#modal-form'; @@ -489,15 +489,11 @@ function barcodeCheckIn(location_id) { success: function(response, status) { // 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', - icon: 'fas fa-times-circle', - }); + location.reload(); } } } From 27dac5af978ee887ae104b3e3dddc0ee9e460946 Mon Sep 17 00:00:00 2001 From: Oliver Date: Wed, 6 Apr 2022 09:42:07 +1000 Subject: [PATCH 4/6] Fix search errors - Do not show API error messages for requests which were intentionally aborted - Prevents a large number of error messages being displayed when search text is changed --- InvenTree/templates/js/translated/api.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/InvenTree/templates/js/translated/api.js b/InvenTree/templates/js/translated/api.js index eadf2e2afc..fccd6bf5ef 100644 --- a/InvenTree/templates/js/translated/api.js +++ b/InvenTree/templates/js/translated/api.js @@ -179,6 +179,11 @@ function showApiError(xhr, url) { var title = null; var message = null; + if (xhr.statusText == 'abort') { + // Don't show errors for requests which were intentionally aborted + return; + } + switch (xhr.status || 0) { // No response case 0: From 24c64d74799d687eb1cdf5e84fd8f40ea2e4a571 Mon Sep 17 00:00:00 2001 From: Oliver Date: Wed, 6 Apr 2022 12:21:19 +1000 Subject: [PATCH 5/6] Bug fix for "inverted" logic when hiding inactive parts from search results --- InvenTree/templates/js/translated/search.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/InvenTree/templates/js/translated/search.js b/InvenTree/templates/js/translated/search.js index c0c1a07db7..4db310a062 100644 --- a/InvenTree/templates/js/translated/search.js +++ b/InvenTree/templates/js/translated/search.js @@ -89,7 +89,8 @@ function updateSearch() { var params = {}; if (user_settings.SEARCH_HIDE_INACTIVE_PARTS) { - params.active = false; + // Return *only* active parts + params.active = true; } // Search for matching parts From ad366ef0bda2ed5dfdc91a32a48d21a7322c0a27 Mon Sep 17 00:00:00 2001 From: eeintech Date: Wed, 6 Apr 2022 16:45:23 -0400 Subject: [PATCH 6/6] Fix part and po files import --- .../order/templates/order/order_wizard/po_upload.html | 10 +++++++--- .../part/templates/part/import_wizard/part_upload.html | 3 +-- InvenTree/templates/patterns/wizard/upload.html | 2 ++ 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/InvenTree/order/templates/order/order_wizard/po_upload.html b/InvenTree/order/templates/order/order_wizard/po_upload.html index b101cfc8b5..d33d27f6c6 100644 --- a/InvenTree/order/templates/order/order_wizard/po_upload.html +++ b/InvenTree/order/templates/order/order_wizard/po_upload.html @@ -11,10 +11,14 @@ {% block page_content %} {% trans "Upload File for Purchase Order" as header_text %} - {% order.status == PurchaseOrderStatus.PENDING and roles.purchase_order.change as upload_go_ahead %} {% trans "Order is already processed. Files cannot be uploaded." as error_text %} - {% "panel-upload-file" as panel_id %} - {% include "patterns/wizard/upload.html" with header_text=header_text upload_go_ahead=upload_go_ahead error_text=error_text panel_id=panel_id %} + {% with "panel-upload-file" as panel_id %} + {% if order.status == PurchaseOrderStatus.PENDING and roles.purchase_order.change %} + {% include "patterns/wizard/upload.html" with header_text=header_text upload_go_ahead=True error_text=error_text panel_id=panel_id %} + {% else %} + {% include "patterns/wizard/upload.html" with header_text=header_text upload_go_ahead=False error_text=error_text panel_id=panel_id %} + {% endif %} + {% endwith %} {% endblock %} {% block js_ready %} diff --git a/InvenTree/part/templates/part/import_wizard/part_upload.html b/InvenTree/part/templates/part/import_wizard/part_upload.html index 4fef625d1d..025a4e997c 100644 --- a/InvenTree/part/templates/part/import_wizard/part_upload.html +++ b/InvenTree/part/templates/part/import_wizard/part_upload.html @@ -11,9 +11,8 @@ {% block content %} {% trans "Import Parts from File" as header_text %} - {% roles.part.change as upload_go_ahead %} {% trans "Unsuffitient privileges." as error_text %} - {% include "patterns/wizard/upload.html" with header_text=header_text upload_go_ahead=upload_go_ahead error_text=error_text %} + {% include "patterns/wizard/upload.html" with header_text=header_text upload_go_ahead=roles.part.change error_text=error_text %} {% endblock %} {% block js_ready %} diff --git a/InvenTree/templates/patterns/wizard/upload.html b/InvenTree/templates/patterns/wizard/upload.html index 11ab48eced..6a7049247d 100644 --- a/InvenTree/templates/patterns/wizard/upload.html +++ b/InvenTree/templates/patterns/wizard/upload.html @@ -1,3 +1,5 @@ +{% load i18n %} +