diff --git a/InvenTree/stock/templates/stock/location.html b/InvenTree/stock/templates/stock/location.html index 7490d262bd..d3cc407298 100644 --- a/InvenTree/stock/templates/stock/location.html +++ b/InvenTree/stock/templates/stock/location.html @@ -243,12 +243,11 @@ }); {% if location %} + $('#location-edit').click(function() { - launchModalForm("{% url 'stock-location-edit' location.id %}", - { - reload: true - }); - return false; + editStockLocation({{ location.id }}, { + reload: true, + }); }); $('#location-delete').click(function() { diff --git a/InvenTree/stock/test_views.py b/InvenTree/stock/test_views.py index 6d22c7e4bb..64d0ac42d5 100644 --- a/InvenTree/stock/test_views.py +++ b/InvenTree/stock/test_views.py @@ -66,10 +66,6 @@ class StockListTest(StockViewTestCase): class StockLocationTest(StockViewTestCase): """ Tests for StockLocation views """ - def test_location_edit(self): - response = self.client.get(reverse('stock-location-edit', args=(1,)), HTTP_X_REQUESTED_WITH='XMLHttpRequest') - self.assertEqual(response.status_code, 200) - 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') @@ -258,12 +254,6 @@ class StockOwnershipTest(StockViewTestCase): # Enable ownership control self.enable_ownership() - # Set ownership on existing location - response = self.client.post(reverse('stock-location-edit', args=(test_location_id,)), - {'name': 'Office', 'owner': user_group_owner.pk}, - HTTP_X_REQUESTED_WITH='XMLHttpRequest') - self.assertContains(response, '"form_valid": true', status_code=200) - """ TODO: Refactor this following test to use the new API form # Set ownership on existing item (and change location) @@ -280,15 +270,6 @@ class StockOwnershipTest(StockViewTestCase): # Login with new user self.client.login(username='john', password='custom123') - # Test location edit - response = self.client.post(reverse('stock-location-edit', args=(test_location_id,)), - {'name': 'Office', 'owner': new_user_group_owner.pk}, - HTTP_X_REQUESTED_WITH='XMLHttpRequest') - - # Make sure the location's owner is unchanged - location = StockLocation.objects.get(pk=test_location_id) - self.assertEqual(location.owner, user_group_owner) - """ TODO: Refactor this following test to use the new API form # Test item edit @@ -370,16 +351,3 @@ class StockOwnershipTest(StockViewTestCase): # Logout self.client.logout() - - # Login with admin - self.client.login(username='username', password='password') - - # Switch owner of location - response = self.client.post(reverse('stock-location-edit', args=(location_created.pk,)), - {'name': new_location['name'], 'owner': user_group_owner.pk}, - HTTP_X_REQUESTED_WITH='XMLHttpRequest') - self.assertContains(response, '"form_valid": true', status_code=200) - - # Check that owner was updated for item in this location - stock_item = StockItem.objects.all().last() - self.assertEqual(stock_item.owner, user_group_owner) diff --git a/InvenTree/stock/urls.py b/InvenTree/stock/urls.py index d3e7090652..58b76b9bf7 100644 --- a/InvenTree/stock/urls.py +++ b/InvenTree/stock/urls.py @@ -11,7 +11,6 @@ location_urls = [ url(r'^new/', views.StockLocationCreate.as_view(), name='stock-location-create'), url(r'^(?P\d+)/', include([ - url(r'^edit/?', views.StockLocationEdit.as_view(), name='stock-location-edit'), url(r'^delete/?', views.StockLocationDelete.as_view(), name='stock-location-delete'), url(r'^qr_code/?', views.StockLocationQRCode.as_view(), name='stock-location-qr'), diff --git a/InvenTree/stock/views.py b/InvenTree/stock/views.py index eb5fabcc25..583ad705db 100644 --- a/InvenTree/stock/views.py +++ b/InvenTree/stock/views.py @@ -149,6 +149,10 @@ class StockLocationEdit(AjaxUpdateView): """ View for editing details of a StockLocation. This view is used with the EditStockLocationForm to deliver a modal form to the web view + + TODO: Remove this code as location editing has been migrated to the API forms + - Have to still validate that all form functionality (as below) as been ported + """ model = StockLocation diff --git a/InvenTree/templates/js/translated/stock.js b/InvenTree/templates/js/translated/stock.js index 174e675426..8d0637238c 100644 --- a/InvenTree/templates/js/translated/stock.js +++ b/InvenTree/templates/js/translated/stock.js @@ -51,13 +51,14 @@ loadStockTestResultsTable, loadStockTrackingTable, loadTableFilters, - locationFields, removeStockRow, + stockItemFields, + stockLocationFields, stockStatusCodes, */ -function locationFields() { +function stockLocationFields(options={}) { return { parent: { help_text: '{% trans "Parent stock location" %}', @@ -68,6 +69,19 @@ function locationFields() { } +/* + * Launch an API form to edit a stock location + */ +function editStockLocation(pk, options={}) { + + var url = `/api/stock/location/${pk}/`; + + options.fields = stockLocationFields(options); + + constructForm(url, options); +} + + function stockItemFields(options={}) { var fields = { part: {},