mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-30 12:36:45 +00:00
Create new stock location via API forms
This commit is contained in:
parent
0d9c08b49c
commit
ef305032c9
@ -222,24 +222,13 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
$('#location-create').click(function () {
|
$('#location-create').click(function () {
|
||||||
launchModalForm("{% url 'stock-location-create' %}",
|
|
||||||
{
|
createStockLocation({
|
||||||
data: {
|
|
||||||
{% if location %}
|
{% if location %}
|
||||||
location: {{ location.id }}
|
parent: {{ location.pk }},
|
||||||
{% endif %}
|
{% endif %}
|
||||||
},
|
|
||||||
follow: true,
|
follow: true,
|
||||||
secondary: [
|
|
||||||
{
|
|
||||||
field: 'parent',
|
|
||||||
label: '{% trans "New Location" %}',
|
|
||||||
title: '{% trans "Create new location" %}',
|
|
||||||
url: "{% url 'stock-location-create' %}",
|
|
||||||
},
|
|
||||||
]
|
|
||||||
});
|
});
|
||||||
return false;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
{% if location %}
|
{% if location %}
|
||||||
|
@ -63,32 +63,6 @@ class StockListTest(StockViewTestCase):
|
|||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
|
||||||
class StockLocationTest(StockViewTestCase):
|
|
||||||
""" Tests for StockLocation views """
|
|
||||||
|
|
||||||
def test_qr_code(self):
|
|
||||||
# Request the StockLocation QR view
|
|
||||||
response = self.client.get(reverse('stock-location-qr', args=(1,)), HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
|
||||||
self.assertEqual(response.status_code, 200)
|
|
||||||
|
|
||||||
# Test for an invalid StockLocation
|
|
||||||
response = self.client.get(reverse('stock-location-qr', args=(999,)), HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
|
||||||
self.assertEqual(response.status_code, 200)
|
|
||||||
|
|
||||||
def test_create(self):
|
|
||||||
# Test StockLocation creation view
|
|
||||||
response = self.client.get(reverse('stock-location-create'), HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
|
||||||
self.assertEqual(response.status_code, 200)
|
|
||||||
|
|
||||||
# Create with a parent
|
|
||||||
response = self.client.get(reverse('stock-location-create'), {'location': 1}, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
|
||||||
self.assertEqual(response.status_code, 200)
|
|
||||||
|
|
||||||
# Create with an invalid parent
|
|
||||||
response = self.client.get(reverse('stock-location-create'), {'location': 999}, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
|
||||||
self.assertEqual(response.status_code, 200)
|
|
||||||
|
|
||||||
|
|
||||||
class StockItemTest(StockViewTestCase):
|
class StockItemTest(StockViewTestCase):
|
||||||
"""" Tests for StockItem views """
|
"""" Tests for StockItem views """
|
||||||
|
|
||||||
@ -289,38 +263,6 @@ class StockOwnershipTest(StockViewTestCase):
|
|||||||
'owner': new_user_group_owner.pk,
|
'owner': new_user_group_owner.pk,
|
||||||
}
|
}
|
||||||
|
|
||||||
# Create new parent location
|
|
||||||
response = self.client.post(reverse('stock-location-create'),
|
|
||||||
parent_location, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
|
||||||
self.assertContains(response, '"form_valid": true', status_code=200)
|
|
||||||
|
|
||||||
# Retrieve created location
|
|
||||||
parent_location = StockLocation.objects.get(name=parent_location['name'])
|
|
||||||
|
|
||||||
# Create new child location
|
|
||||||
new_location = {
|
|
||||||
'name': 'Upper Left Drawer',
|
|
||||||
'description': 'John\'s desk - Upper left drawer',
|
|
||||||
}
|
|
||||||
|
|
||||||
# Try to create new location with neither parent or owner
|
|
||||||
response = self.client.post(reverse('stock-location-create'),
|
|
||||||
new_location, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
|
||||||
self.assertContains(response, '"form_valid": false', status_code=200)
|
|
||||||
|
|
||||||
# Try to create new location with invalid owner
|
|
||||||
new_location['parent'] = parent_location.id
|
|
||||||
new_location['owner'] = user_group_owner.pk
|
|
||||||
response = self.client.post(reverse('stock-location-create'),
|
|
||||||
new_location, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
|
||||||
self.assertContains(response, '"form_valid": false', status_code=200)
|
|
||||||
|
|
||||||
# Try to create new location with valid owner
|
|
||||||
new_location['owner'] = new_user_group_owner.pk
|
|
||||||
response = self.client.post(reverse('stock-location-create'),
|
|
||||||
new_location, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
|
||||||
self.assertContains(response, '"form_valid": true', status_code=200)
|
|
||||||
|
|
||||||
# Retrieve created location
|
# Retrieve created location
|
||||||
location_created = StockLocation.objects.get(name=new_location['name'])
|
location_created = StockLocation.objects.get(name=new_location['name'])
|
||||||
|
|
||||||
|
@ -8,8 +8,6 @@ from stock import views
|
|||||||
|
|
||||||
location_urls = [
|
location_urls = [
|
||||||
|
|
||||||
url(r'^new/', views.StockLocationCreate.as_view(), name='stock-location-create'),
|
|
||||||
|
|
||||||
url(r'^(?P<pk>\d+)/', include([
|
url(r'^(?P<pk>\d+)/', include([
|
||||||
url(r'^delete/?', views.StockLocationDelete.as_view(), name='stock-location-delete'),
|
url(r'^delete/?', views.StockLocationDelete.as_view(), name='stock-location-delete'),
|
||||||
url(r'^qr_code/?', views.StockLocationQRCode.as_view(), name='stock-location-qr'),
|
url(r'^qr_code/?', views.StockLocationQRCode.as_view(), name='stock-location-qr'),
|
||||||
|
@ -931,6 +931,10 @@ class StockLocationCreate(AjaxCreateView):
|
|||||||
"""
|
"""
|
||||||
View for creating a new StockLocation
|
View for creating a new StockLocation
|
||||||
A parent location (another StockLocation object) can be passed as a query parameter
|
A parent location (another StockLocation object) can be passed as a query parameter
|
||||||
|
|
||||||
|
TODO: Remove this class entirely, as it has been migrated to the API forms
|
||||||
|
- Still need to check that all the functionality (as below) has been implemented
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
model = StockLocation
|
model = StockLocation
|
||||||
|
@ -59,13 +59,19 @@
|
|||||||
|
|
||||||
|
|
||||||
function stockLocationFields(options={}) {
|
function stockLocationFields(options={}) {
|
||||||
return {
|
var fields = {
|
||||||
parent: {
|
parent: {
|
||||||
help_text: '{% trans "Parent stock location" %}',
|
help_text: '{% trans "Parent stock location" %}',
|
||||||
},
|
},
|
||||||
name: {},
|
name: {},
|
||||||
description: {},
|
description: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (options.parent) {
|
||||||
|
fields.parent.value = options.parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
return fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -82,6 +88,20 @@ function editStockLocation(pk, options={}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Launch an API form to create a new stock location
|
||||||
|
*/
|
||||||
|
function createStockLocation(options={}) {
|
||||||
|
|
||||||
|
var url = '{% url "api-location-list" %}';
|
||||||
|
|
||||||
|
options.method = 'POST';
|
||||||
|
options.fields = stockLocationFields(options);
|
||||||
|
|
||||||
|
constructForm(url, options);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function stockItemFields(options={}) {
|
function stockItemFields(options={}) {
|
||||||
var fields = {
|
var fields = {
|
||||||
part: {},
|
part: {},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user