2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-01 03:00:54 +00:00

Refactor all "adjustment" forms to use the new API approach

This commit is contained in:
Oliver
2021-07-12 20:38:54 +10:00
parent 74e5b2cd3f
commit 9fc7976569
6 changed files with 56 additions and 83 deletions

View File

@ -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

View File

@ -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();
}
});
}
}
);
}

View File

@ -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() {

View File

@ -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')