diff --git a/InvenTree/part/templates/part/part_base.html b/InvenTree/part/templates/part/part_base.html index 53ab0aaf14..413f761cb9 100644 --- a/InvenTree/part/templates/part/part_base.html +++ b/InvenTree/part/templates/part/part_base.html @@ -273,13 +273,25 @@ }); $("#part-count").click(function() { - launchModalForm("/stock/adjust/", { - data: { - action: "count", + inventreeGet( + '{% url "api-stock-list" %}', + { part: {{ part.id }}, + in_stock: true, + allow_variants: true, + part_detail: true, + location_detail: true, }, - reload: true, - }); + { + success: function(items) { + adjustStock('count', items, { + onSuccess: function() { + location.reload(); + } + }); + }, + } + ); }); $("#price-button").click(function() { diff --git a/InvenTree/stock/api.py b/InvenTree/stock/api.py index 34314ac8c4..91810dddc6 100644 --- a/InvenTree/stock/api.py +++ b/InvenTree/stock/api.py @@ -481,13 +481,6 @@ class StockList(generics.ListCreateAPIView): - GET: Return a list of all StockItem objects (with optional query filters) - POST: Create a new StockItem - - Additional query parameters are available: - - location: Filter stock by location - - category: Filter by parts belonging to a certain category - - supplier: Filter by supplier - - ancestor: Filter by an 'ancestor' StockItem - - status: Filter by the StockItem status """ serializer_class = StockItemSerializer diff --git a/InvenTree/stock/templates/stock/item_base.html b/InvenTree/stock/templates/stock/item_base.html index 2eb7695498..979c54ba28 100644 --- a/InvenTree/stock/templates/stock/item_base.html +++ b/InvenTree/stock/templates/stock/item_base.html @@ -534,14 +534,21 @@ $("#barcode-scan-into-location").click(function() { }); function itemAdjust(action) { - launchModalForm("/stock/adjust/", + + inventreeGet( + '{% url "api-stock-detail" item.pk %}', { - data: { - action: action, - item: {{ item.id }}, - }, - reload: true, - follow: true, + part_detail: true, + location_detail: true, + }, + { + success: function(item) { + adjustStock(action, [item], { + onSuccess: function() { + location.reload(); + } + }); + } } ); } diff --git a/InvenTree/stock/templates/stock/location.html b/InvenTree/stock/templates/stock/location.html index 6a69be260e..889e7a2c98 100644 --- a/InvenTree/stock/templates/stock/location.html +++ b/InvenTree/stock/templates/stock/location.html @@ -216,13 +216,25 @@ {% if location %} $("#location-count").click(function() { - launchModalForm("/stock/adjust/", { - data: { - action: "count", + + inventreeGet( + '{% url "api-stock-list" %}', + { location: {{ location.id }}, - reload: true, + in_stock: true, + part_detail: true, + location_detail: true, + }, + { + success: function(items) { + adjustStock('count', items, { + onSuccess: function() { + location.reload(); + } + }); + } } - }); + ); }); $('#print-label').click(function() { diff --git a/InvenTree/stock/test_views.py b/InvenTree/stock/test_views.py index c565532739..9494598430 100644 --- a/InvenTree/stock/test_views.py +++ b/InvenTree/stock/test_views.py @@ -105,31 +105,6 @@ class StockItemTest(StockViewTestCase): response = self.client.get(reverse('stock-item-qr', args=(9999,)), HTTP_X_REQUESTED_WITH='XMLHttpRequest') self.assertEqual(response.status_code, 200) - def test_adjust_items(self): - url = reverse('stock-adjust') - - # Move items - response = self.client.get(url, {'stock[]': [1, 2, 3, 4, 5], 'action': 'move'}, HTTP_X_REQUESTED_WITH='XMLHttpRequest') - self.assertEqual(response.status_code, 200) - - # Count part - response = self.client.get(url, {'part': 1}, HTTP_X_REQUESTED_WITH='XMLHttpRequest') - self.assertEqual(response.status_code, 200) - - # Remove items - response = self.client.get(url, {'location': 1, 'action': 'take'}, HTTP_X_REQUESTED_WITH='XMLHttpRequest') - self.assertEqual(response.status_code, 200) - - # Add items - response = self.client.get(url, {'item': 1, 'action': 'add'}, HTTP_X_REQUESTED_WITH='XMLHttpRequest') - self.assertEqual(response.status_code, 200) - - # Blank response - response = self.client.get(url, HTTP_X_REQUESTED_WITH='XMLHttpRequest') - self.assertEqual(response.status_code, 200) - - # TODO - Tests for POST data - def test_edit_item(self): # Test edit view for StockItem response = self.client.get(reverse('stock-item-edit', args=(1,)), HTTP_X_REQUESTED_WITH='XMLHttpRequest') diff --git a/InvenTree/templates/js/stock.js b/InvenTree/templates/js/stock.js index cf41c1a9cb..6ce4c3aae4 100644 --- a/InvenTree/templates/js/stock.js +++ b/InvenTree/templates/js/stock.js @@ -23,7 +23,7 @@ function stockStatusCodes() { /** * Perform stock adjustments */ -function adjustStock(items, options={}) { +function adjustStock(action, items, options={}) { var formTitle = 'Form Title Here'; var actionTitle = null; @@ -34,7 +34,7 @@ function adjustStock(items, options={}) { var specifyLocation = false; var allowSerializedStock = false; - switch (options.action) { + switch (action) { case 'move': formTitle = '{% trans "Transfer Stock" %}'; actionTitle = '{% trans "Move" %}'; @@ -97,7 +97,7 @@ function adjustStock(items, options={}) { var maxValue = null; var value = null; - switch (options.action) { + switch (action) { case 'move': minValue = 0; maxValue = item.quantity; @@ -224,7 +224,7 @@ function adjustStock(items, options={}) { onSubmit: function(fields, opts) { // "Delete" action gets handled differently - if (options.action == 'delete') { + if (action == 'delete') { var requests = []; @@ -259,7 +259,9 @@ function adjustStock(items, options={}) { var q = getFormFieldValue(item.pk, {}, {modal: modal}); - data.items.push({pk: item.pk, quantity: q}) + if (q != null) { + data.items.push({pk: item.pk, quantity: q}); + } }); // Add in extra field data @@ -1053,39 +1055,11 @@ function loadStockTable(table, options) { function stockAdjustment(action) { var items = $("#stock-table").bootstrapTable("getSelections"); - adjustStock(items, { - action: action, + adjustStock(action, items, { onSuccess: function() { $('#stock-table').bootstrapTable('refresh'); } }); - - return; - - // Buttons for launching secondary modals - var secondary = []; - - if (action == 'move') { - secondary.push({ - field: 'destination', - label: '{% trans "New Location" %}', - title: '{% trans "Create new location" %}', - url: "/stock/location/new/", - }); - } - - launchModalForm("/stock/adjust/", - { - data: { - action: action, - stock: stock, - }, - success: function() { - $("#stock-table").bootstrapTable('refresh'); - }, - secondary: secondary, - } - ); } // Automatically link button callbacks