mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Refactor all "adjustment" forms to use the new API approach
This commit is contained in:
parent
74e5b2cd3f
commit
9fc7976569
@ -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() {
|
||||
|
@ -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
|
||||
|
@ -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 }},
|
||||
part_detail: true,
|
||||
location_detail: true,
|
||||
},
|
||||
reload: true,
|
||||
follow: true,
|
||||
{
|
||||
success: function(item) {
|
||||
adjustStock(action, [item], {
|
||||
onSuccess: function() {
|
||||
location.reload();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
@ -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() {
|
||||
|
@ -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')
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user