diff --git a/InvenTree/stock/api.py b/InvenTree/stock/api.py index 534d27a8f4..b946d66aa5 100644 --- a/InvenTree/stock/api.py +++ b/InvenTree/stock/api.py @@ -940,6 +940,15 @@ class StockAttachmentDetail(generics.RetrieveUpdateDestroyAPIView, AttachmentMix serializer_class = StockItemAttachmentSerializer +class StockItemTestResultDetail(generics.RetrieveUpdateDestroyAPIView): + """ + Detail endpoint for StockItemTestResult + """ + + queryset = StockItemTestResult.objects.all() + serializer_class = StockItemTestResultSerializer + + class StockItemTestResultList(generics.ListCreateAPIView): """ API endpoint for listing (and creating) a StockItemTestResult object. @@ -1156,6 +1165,7 @@ stock_api_urls = [ # Base URL for StockItemTestResult API endpoints url(r'^test/', include([ + url(r'^(?P\d+)/', StockItemTestResultDetail.as_view(), name='api-stock-test-result-detail'), url(r'^$', StockItemTestResultList.as_view(), name='api-stock-test-result-list'), ])), diff --git a/InvenTree/stock/forms.py b/InvenTree/stock/forms.py index 92089623f9..ec3eee09d5 100644 --- a/InvenTree/stock/forms.py +++ b/InvenTree/stock/forms.py @@ -23,22 +23,6 @@ from report.models import TestReport from part.models import Part from .models import StockLocation, StockItem, StockItemTracking -from .models import StockItemAttachment -from .models import StockItemTestResult - - -class EditStockItemAttachmentForm(HelperForm): - """ - Form for creating / editing a StockItemAttachment object - """ - - class Meta: - model = StockItemAttachment - fields = [ - 'stock_item', - 'attachment', - 'comment' - ] class AssignStockItemToCustomerForm(HelperForm): @@ -65,23 +49,6 @@ class ReturnStockItemForm(HelperForm): ] -class EditStockItemTestResultForm(HelperForm): - """ - Form for creating / editing a StockItemTestResult object. - """ - - class Meta: - model = StockItemTestResult - fields = [ - 'stock_item', - 'test', - 'result', - 'value', - 'attachment', - 'notes', - ] - - class EditStockLocationForm(HelperForm): """ Form for editing a StockLocation """ diff --git a/InvenTree/stock/templates/stock/item_tests.html b/InvenTree/stock/templates/stock/item_tests.html index 4b3d9dd028..d7d26fcbba 100644 --- a/InvenTree/stock/templates/stock/item_tests.html +++ b/InvenTree/stock/templates/stock/item_tests.html @@ -48,8 +48,7 @@ loadStockTestResultsTable( ); function reloadTable() { - location.reload(); - //$("#test-result-table").bootstrapTable("refresh"); + $("#test-result-table").bootstrapTable("refresh"); } {% if item.has_test_reports %} @@ -70,15 +69,23 @@ $("#delete-test-results").click(function() { {% endif %} $("#add-test-result").click(function() { - launchModalForm( - "{% url 'stock-item-test-create' %}", { - data: { - stock_item: {{ item.id }}, - }, - success: reloadTable, - focus: 'test', - } - ); + + constructForm('{% url "api-stock-test-result-list" %}', { + method: 'POST', + fields: { + test: {}, + result: {}, + value: {}, + attachment: {}, + notes: {}, + stock_item: { + value: {{ item.pk }}, + hidden: true, + } + }, + title: '{% trans "Add Test Result" %}', + onSuccess: reloadTable, + }); }); $("#test-result-table").on('click', '.button-test-add', function() { @@ -86,35 +93,57 @@ $("#test-result-table").on('click', '.button-test-add', function() { var test_name = button.attr('pk'); - launchModalForm( - "{% url 'stock-item-test-create' %}", { - data: { - stock_item: {{ item.id }}, - test: test_name + constructForm('{% url "api-stock-test-result-list" %}', { + method: 'POST', + fields: { + test: { + value: test_name, }, - success: reloadTable, - focus: 'value', - } - ); + result: {}, + value: {}, + attachment: {}, + notes: {}, + stock_item: { + value: {{ item.pk }}, + hidden: true, + } + }, + title: '{% trans "Add Test Result" %}', + onSuccess: reloadTable, + }); }); $("#test-result-table").on('click', '.button-test-edit', function() { var button = $(this); - var url = `/stock/item/test/${button.attr('pk')}/edit/`; + var pk = button.attr('pk'); - launchModalForm(url, { - success: reloadTable, + var url = `/api/stock/test/${pk}/`; + + constructForm(url, { + fields: { + test: {}, + result: {}, + value: {}, + attachment: {}, + notes: {}, + }, + title: '{% trans "Edit Test Result" %}', + onSuccess: reloadTable, }); }); $("#test-result-table").on('click', '.button-test-delete', function() { var button = $(this); - var url = `/stock/item/test/${button.attr('pk')}/delete/`; + var pk = button.attr('pk'); - launchModalForm(url, { - success: reloadTable, + var url = `/api/stock/test/${pk}/`; + + constructForm(url, { + method: 'DELETE', + title: '{% trans "Delete Test Result" %}', + onSuccess: reloadTable, }); }); diff --git a/InvenTree/stock/urls.py b/InvenTree/stock/urls.py index 3e38d48f0e..ac9474f805 100644 --- a/InvenTree/stock/urls.py +++ b/InvenTree/stock/urls.py @@ -62,13 +62,6 @@ stock_urls = [ url(r'^item/uninstall/', views.StockItemUninstall.as_view(), name='stock-item-uninstall'), - # URLs for StockItem tests - url(r'^item/test/', include([ - url(r'^new/', views.StockItemTestResultCreate.as_view(), name='stock-item-test-create'), - url(r'^(?P\d+)/edit/', views.StockItemTestResultEdit.as_view(), name='stock-item-test-edit'), - url(r'^(?P\d+)/delete/', views.StockItemTestResultDelete.as_view(), name='stock-item-test-delete'), - ])), - url(r'^track/', include(stock_tracking_urls)), url(r'^adjust/?', views.StockAdjust.as_view(), name='stock-adjust'), diff --git a/InvenTree/stock/views.py b/InvenTree/stock/views.py index e8a3b8614c..eca7485c40 100644 --- a/InvenTree/stock/views.py +++ b/InvenTree/stock/views.py @@ -355,74 +355,6 @@ class StockItemDeleteTestData(AjaxUpdateView): return self.renderJsonResponse(request, form, data) -class StockItemTestResultCreate(AjaxCreateView): - """ - View for adding a new StockItemTestResult - """ - - model = StockItemTestResult - form_class = StockForms.EditStockItemTestResultForm - ajax_form_title = _("Add Test Result") - - def save(self, form, **kwargs): - """ - Record the user that uploaded the test result - """ - - result = form.save(commit=False) - result.user = self.request.user - result.save() - - def get_initial(self): - - initials = super().get_initial() - - try: - stock_id = self.request.GET.get('stock_item', None) - initials['stock_item'] = StockItem.objects.get(pk=stock_id) - except (ValueError, StockItem.DoesNotExist): - pass - - initials['test'] = self.request.GET.get('test', '') - - return initials - - def get_form(self): - - form = super().get_form() - form.fields['stock_item'].widget = HiddenInput() - - return form - - -class StockItemTestResultEdit(AjaxUpdateView): - """ - View for editing a StockItemTestResult - """ - - model = StockItemTestResult - form_class = StockForms.EditStockItemTestResultForm - ajax_form_title = _("Edit Test Result") - - def get_form(self): - - form = super().get_form() - - form.fields['stock_item'].widget = HiddenInput() - - return form - - -class StockItemTestResultDelete(AjaxDeleteView): - """ - View for deleting a StockItemTestResult - """ - - model = StockItemTestResult - ajax_form_title = _("Delete Test Result") - context_object_name = "result" - - class StockExportOptions(AjaxView): """ Form for selecting StockExport options """