mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Refactor forms for StockItemTestResult
- Add DETAIL endpoint for model - Remove old views - Remove old forms
This commit is contained in:
parent
59b794f0e5
commit
bb0a72f235
@ -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<pk>\d+)/', StockItemTestResultDetail.as_view(), name='api-stock-test-result-detail'),
|
||||
url(r'^$', StockItemTestResultList.as_view(), name='api-stock-test-result-list'),
|
||||
])),
|
||||
|
||||
|
@ -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 """
|
||||
|
||||
|
@ -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,
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -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<pk>\d+)/edit/', views.StockItemTestResultEdit.as_view(), name='stock-item-test-edit'),
|
||||
url(r'^(?P<pk>\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'),
|
||||
|
@ -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 """
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user