From aac835f634e8427c7c9689523a5d9e8ed8bef867 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Thu, 14 Jan 2021 13:41:38 +1100 Subject: [PATCH 1/2] Add menu item to set stock status for multiple items --- InvenTree/templates/js/stock.js | 8 ++++++++ InvenTree/templates/stock_table.html | 1 + 2 files changed, 9 insertions(+) diff --git a/InvenTree/templates/js/stock.js b/InvenTree/templates/js/stock.js index 9ce395db57..bc2db4098a 100644 --- a/InvenTree/templates/js/stock.js +++ b/InvenTree/templates/js/stock.js @@ -682,6 +682,14 @@ function loadStockTable(table, options) { }); }); + $("#multi-item-set-status").click(function() { + var selections = $("#stock-table").bootstrapTable('getSelections'); + + selections.forEach(function(item) { + // TODO + }); + }); + $("#multi-item-delete").click(function() { var selections = $("#stock-table").bootstrapTable("getSelections"); diff --git a/InvenTree/templates/stock_table.html b/InvenTree/templates/stock_table.html index 51f7c277db..f39f9c733a 100644 --- a/InvenTree/templates/stock_table.html +++ b/InvenTree/templates/stock_table.html @@ -23,6 +23,7 @@
  • {% trans "Count stock" %}
  • {% trans "Move stock" %}
  • {% trans "Order stock" %}
  • +
  • {% trans "Change stock status" %}
  • {% endif %} {% if roles.stock.delete %}
  • {% trans "Delete Stock" %}
  • From bb9fe98a7edd50d07b41e02730549f6e358f1b92 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Thu, 14 Jan 2021 14:04:24 +1100 Subject: [PATCH 2/2] Set status for multiple stock items at once --- InvenTree/templates/js/stock.js | 97 +++++++++++++++++++++++++++++++-- 1 file changed, 93 insertions(+), 4 deletions(-) diff --git a/InvenTree/templates/js/stock.js b/InvenTree/templates/js/stock.js index bc2db4098a..e9cb5e2696 100644 --- a/InvenTree/templates/js/stock.js +++ b/InvenTree/templates/js/stock.js @@ -6,8 +6,18 @@ * Requires api.js to be loaded first */ -/* Functions for interacting with stock management forms - */ + +function stockStatusCodes() { + return [ + {% for code in StockStatus.list %} + { + key: {{ code.key }}, + text: "{{ code.value }}", + }, + {% endfor %} + ]; +} + function removeStockRow(e) { // Remove a selected row from a stock modal form @@ -683,11 +693,90 @@ function loadStockTable(table, options) { }); $("#multi-item-set-status").click(function() { + // Select and set the STATUS field for selected stock items var selections = $("#stock-table").bootstrapTable('getSelections'); - selections.forEach(function(item) { - // TODO + // Select stock status + var modal = '#modal-form'; + + var status_list = makeOptionsList( + stockStatusCodes(), + function(item) { + return item.text; + }, + function (item) { + return item.key; + } + ); + + // Add an empty option at the start of the list + status_list.unshift(''); + + // Construct form + var html = ` +
    +
    + +
    + +
    +
    +
    `; + + openModal({ + modal: modal, }); + + modalEnable(modal, true); + modalSetTitle(modal, '{% trans "Set Stock Status" %}'); + modalSetContent(modal, html); + + attachSelect(modal); + + modalSubmit(modal, function() { + var label = $(modal).find('#id_status'); + + var status_code = label.val(); + + closeModal(modal); + + if (!status_code) { + showAlertDialog( + '{% trans "Select Status Code" %}', + '{% trans "Status code must be selected" %}' + ); + + return; + } + + var requests = []; + + selections.forEach(function(item) { + var url = `/api/stock/${item.pk}/`; + + requests.push( + inventreePut( + url, + { + status: status_code, + }, + { + method: 'PATCH', + success: function() { + } + } + ) + ); + }); + + $.when.apply($, requests).then(function() { + $("#stock-table").bootstrapTable('refresh'); + }); + }) }); $("#multi-item-delete").click(function() {