mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Add forms / views / etc to create / edit / delete test results manually
This commit is contained in:
parent
82fe497787
commit
327682b719
@ -15,7 +15,9 @@ from InvenTree.helpers import GetExportFormats
|
|||||||
from InvenTree.forms import HelperForm
|
from InvenTree.forms import HelperForm
|
||||||
from InvenTree.fields import RoundingDecimalFormField
|
from InvenTree.fields import RoundingDecimalFormField
|
||||||
|
|
||||||
from .models import StockLocation, StockItem, StockItemTracking, StockItemAttachment
|
from .models import StockLocation, StockItem, StockItemTracking
|
||||||
|
from .models import StockItemAttachment
|
||||||
|
from .models import StockItemTestResult
|
||||||
|
|
||||||
|
|
||||||
class EditStockItemAttachmentForm(HelperForm):
|
class EditStockItemAttachmentForm(HelperForm):
|
||||||
@ -32,6 +34,22 @@ class EditStockItemAttachmentForm(HelperForm):
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class EditStockItemTestResultForm(HelperForm):
|
||||||
|
"""
|
||||||
|
Form for creating / editing a StockItemTestResult object.
|
||||||
|
"""
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = StockItemTestResult
|
||||||
|
fields = [
|
||||||
|
'stock_item',
|
||||||
|
'test',
|
||||||
|
'result',
|
||||||
|
'value',
|
||||||
|
'notes',
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
class EditStockLocationForm(HelperForm):
|
class EditStockLocationForm(HelperForm):
|
||||||
""" Form for editing a StockLocation """
|
""" Form for editing a StockLocation """
|
||||||
|
|
||||||
|
@ -12,7 +12,9 @@
|
|||||||
|
|
||||||
<div id='button-toolbar'>
|
<div id='button-toolbar'>
|
||||||
<div class='button-toolbar container-fluid' style="float: right;">
|
<div class='button-toolbar container-fluid' style="float: right;">
|
||||||
<!-- TODO - Add a button here to manually upload a new test result -->
|
<div class='btn-group' role='group'>
|
||||||
|
<button type='button' class='btn btn-success' id='add-test-result'>{% trans "Add Test Result" %}</button>
|
||||||
|
</div>
|
||||||
<div class='filter-list' id='filter-list-stocktests'>
|
<div class='filter-list' id='filter-list-stocktests'>
|
||||||
<!-- Empty div -->
|
<!-- Empty div -->
|
||||||
</div>
|
</div>
|
||||||
@ -36,4 +38,39 @@ loadStockTestResultsTable(
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
function reloadTable() {
|
||||||
|
$("#test-result-table").bootstrapTable("refresh");
|
||||||
|
}
|
||||||
|
|
||||||
|
$("#add-test-result").click(function() {
|
||||||
|
launchModalForm(
|
||||||
|
"{% url 'stock-item-test-create' %}", {
|
||||||
|
data: {
|
||||||
|
stock_item: {{ item.id }},
|
||||||
|
},
|
||||||
|
success: reloadTable,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#test-result-table").on('click', '.button-test-edit', function() {
|
||||||
|
var button = $(this);
|
||||||
|
|
||||||
|
var url = `/stock/item/test/${button.attr('pk')}/edit/`;
|
||||||
|
|
||||||
|
launchModalForm(url, {
|
||||||
|
success: reloadTable,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#test-result-table").on('click', '.button-test-delete', function() {
|
||||||
|
var button = $(this);
|
||||||
|
|
||||||
|
var url = `/stock/item/test/${button.attr('pk')}/delete/`;
|
||||||
|
|
||||||
|
launchModalForm(url, {
|
||||||
|
success: reloadTable,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
@ -52,12 +52,20 @@ stock_urls = [
|
|||||||
|
|
||||||
url(r'^item/new/?', views.StockItemCreate.as_view(), name='stock-item-create'),
|
url(r'^item/new/?', views.StockItemCreate.as_view(), name='stock-item-create'),
|
||||||
|
|
||||||
|
# URLs for StockItem attachments
|
||||||
url(r'^item/attachment/', include([
|
url(r'^item/attachment/', include([
|
||||||
url(r'^new/', views.StockItemAttachmentCreate.as_view(), name='stock-item-attachment-create'),
|
url(r'^new/', views.StockItemAttachmentCreate.as_view(), name='stock-item-attachment-create'),
|
||||||
url(r'^(?P<pk>\d+)/edit/', views.StockItemAttachmentEdit.as_view(), name='stock-item-attachment-edit'),
|
url(r'^(?P<pk>\d+)/edit/', views.StockItemAttachmentEdit.as_view(), name='stock-item-attachment-edit'),
|
||||||
url(r'^(?P<pk>\d+)/delete/', views.StockItemAttachmentDelete.as_view(), name='stock-item-attachment-delete'),
|
url(r'^(?P<pk>\d+)/delete/', views.StockItemAttachmentDelete.as_view(), name='stock-item-attachment-delete'),
|
||||||
])),
|
])),
|
||||||
|
|
||||||
|
# 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'),
|
||||||
|
@ -26,7 +26,7 @@ from datetime import datetime
|
|||||||
|
|
||||||
from company.models import Company, SupplierPart
|
from company.models import Company, SupplierPart
|
||||||
from part.models import Part
|
from part.models import Part
|
||||||
from .models import StockItem, StockLocation, StockItemTracking, StockItemAttachment
|
from .models import StockItem, StockLocation, StockItemTracking, StockItemAttachment, StockItemTestResult
|
||||||
|
|
||||||
from .admin import StockItemResource
|
from .admin import StockItemResource
|
||||||
|
|
||||||
@ -38,6 +38,7 @@ from .forms import TrackingEntryForm
|
|||||||
from .forms import SerializeStockForm
|
from .forms import SerializeStockForm
|
||||||
from .forms import ExportOptionsForm
|
from .forms import ExportOptionsForm
|
||||||
from .forms import EditStockItemAttachmentForm
|
from .forms import EditStockItemAttachmentForm
|
||||||
|
from .forms import EditStockItemTestResultForm
|
||||||
|
|
||||||
|
|
||||||
class StockIndex(ListView):
|
class StockIndex(ListView):
|
||||||
@ -228,6 +229,68 @@ class StockItemAttachmentDelete(AjaxDeleteView):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class StockItemTestResultCreate(AjaxCreateView):
|
||||||
|
"""
|
||||||
|
View for adding a new StockItemTestResult
|
||||||
|
"""
|
||||||
|
|
||||||
|
model = StockItemTestResult
|
||||||
|
form_class = EditStockItemTestResultForm
|
||||||
|
ajax_form_title = _("Add Test Result")
|
||||||
|
|
||||||
|
def post_save(self, **kwargs):
|
||||||
|
""" Record the user that uploaded the test result """
|
||||||
|
|
||||||
|
self.object.user = self.request.user
|
||||||
|
self.object.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
|
||||||
|
|
||||||
|
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 = 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 """
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
<td>
|
<td>
|
||||||
<div class='btn-group' style='float: right;'>
|
<div class='btn-group' style='float: right;'>
|
||||||
<button type='button' class='btn btn-default btn-glyph attachment-edit-button' pk="{{ attachment.id }}" data-toggle='tooltip' title='{% trans "Edit attachment" %}'>
|
<button type='button' class='btn btn-default btn-glyph attachment-edit-button' pk="{{ attachment.id }}" data-toggle='tooltip' title='{% trans "Edit attachment" %}'>
|
||||||
<span class='fas fa-edit'/>
|
<span class='fas fa-edit icon-blue'/>
|
||||||
</button>
|
</button>
|
||||||
<button type='button' class='btn btn-default btn-glyph attachment-delete-button' pk="{{ attachment.id }}" data-toggle='tooltip' title='{% trans "Delete attachment" %}'>
|
<button type='button' class='btn btn-default btn-glyph attachment-delete-button' pk="{{ attachment.id }}" data-toggle='tooltip' title='{% trans "Delete attachment" %}'>
|
||||||
<span class='fas fa-trash-alt icon-red'/>
|
<span class='fas fa-trash-alt icon-red'/>
|
||||||
|
Loading…
Reference in New Issue
Block a user