mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-30 12:36:45 +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
|
serializer_class = StockItemAttachmentSerializer
|
||||||
|
|
||||||
|
|
||||||
|
class StockItemTestResultDetail(generics.RetrieveUpdateDestroyAPIView):
|
||||||
|
"""
|
||||||
|
Detail endpoint for StockItemTestResult
|
||||||
|
"""
|
||||||
|
|
||||||
|
queryset = StockItemTestResult.objects.all()
|
||||||
|
serializer_class = StockItemTestResultSerializer
|
||||||
|
|
||||||
|
|
||||||
class StockItemTestResultList(generics.ListCreateAPIView):
|
class StockItemTestResultList(generics.ListCreateAPIView):
|
||||||
"""
|
"""
|
||||||
API endpoint for listing (and creating) a StockItemTestResult object.
|
API endpoint for listing (and creating) a StockItemTestResult object.
|
||||||
@ -1156,6 +1165,7 @@ stock_api_urls = [
|
|||||||
|
|
||||||
# Base URL for StockItemTestResult API endpoints
|
# Base URL for StockItemTestResult API endpoints
|
||||||
url(r'^test/', include([
|
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'),
|
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 part.models import Part
|
||||||
|
|
||||||
from .models import StockLocation, StockItem, StockItemTracking
|
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):
|
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):
|
class EditStockLocationForm(HelperForm):
|
||||||
""" Form for editing a StockLocation """
|
""" Form for editing a StockLocation """
|
||||||
|
|
||||||
|
@ -48,8 +48,7 @@ loadStockTestResultsTable(
|
|||||||
);
|
);
|
||||||
|
|
||||||
function reloadTable() {
|
function reloadTable() {
|
||||||
location.reload();
|
$("#test-result-table").bootstrapTable("refresh");
|
||||||
//$("#test-result-table").bootstrapTable("refresh");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{% if item.has_test_reports %}
|
{% if item.has_test_reports %}
|
||||||
@ -70,15 +69,23 @@ $("#delete-test-results").click(function() {
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
$("#add-test-result").click(function() {
|
$("#add-test-result").click(function() {
|
||||||
launchModalForm(
|
|
||||||
"{% url 'stock-item-test-create' %}", {
|
constructForm('{% url "api-stock-test-result-list" %}', {
|
||||||
data: {
|
method: 'POST',
|
||||||
stock_item: {{ item.id }},
|
fields: {
|
||||||
},
|
test: {},
|
||||||
success: reloadTable,
|
result: {},
|
||||||
focus: 'test',
|
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() {
|
$("#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');
|
var test_name = button.attr('pk');
|
||||||
|
|
||||||
launchModalForm(
|
constructForm('{% url "api-stock-test-result-list" %}', {
|
||||||
"{% url 'stock-item-test-create' %}", {
|
method: 'POST',
|
||||||
data: {
|
fields: {
|
||||||
stock_item: {{ item.id }},
|
test: {
|
||||||
test: test_name
|
value: test_name,
|
||||||
},
|
},
|
||||||
success: reloadTable,
|
result: {},
|
||||||
focus: 'value',
|
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() {
|
$("#test-result-table").on('click', '.button-test-edit', function() {
|
||||||
var button = $(this);
|
var button = $(this);
|
||||||
|
|
||||||
var url = `/stock/item/test/${button.attr('pk')}/edit/`;
|
var pk = button.attr('pk');
|
||||||
|
|
||||||
launchModalForm(url, {
|
var url = `/api/stock/test/${pk}/`;
|
||||||
success: reloadTable,
|
|
||||||
|
constructForm(url, {
|
||||||
|
fields: {
|
||||||
|
test: {},
|
||||||
|
result: {},
|
||||||
|
value: {},
|
||||||
|
attachment: {},
|
||||||
|
notes: {},
|
||||||
|
},
|
||||||
|
title: '{% trans "Edit Test Result" %}',
|
||||||
|
onSuccess: reloadTable,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#test-result-table").on('click', '.button-test-delete', function() {
|
$("#test-result-table").on('click', '.button-test-delete', function() {
|
||||||
var button = $(this);
|
var button = $(this);
|
||||||
|
|
||||||
var url = `/stock/item/test/${button.attr('pk')}/delete/`;
|
var pk = button.attr('pk');
|
||||||
|
|
||||||
launchModalForm(url, {
|
var url = `/api/stock/test/${pk}/`;
|
||||||
success: reloadTable,
|
|
||||||
|
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'),
|
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'^track/', include(stock_tracking_urls)),
|
||||||
|
|
||||||
url(r'^adjust/?', views.StockAdjust.as_view(), name='stock-adjust'),
|
url(r'^adjust/?', views.StockAdjust.as_view(), name='stock-adjust'),
|
||||||
|
@ -355,74 +355,6 @@ class StockItemDeleteTestData(AjaxUpdateView):
|
|||||||
return self.renderJsonResponse(request, form, data)
|
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):
|
class StockExportOptions(AjaxView):
|
||||||
""" Form for selecting StockExport options """
|
""" Form for selecting StockExport options """
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user