diff --git a/InvenTree/part/forms.py b/InvenTree/part/forms.py index 4d70ab927a..d72d29669b 100644 --- a/InvenTree/part/forms.py +++ b/InvenTree/part/forms.py @@ -15,6 +15,7 @@ from django.utils.translation import ugettext as _ from .models import Part, PartCategory, PartAttachment from .models import BomItem from .models import PartParameterTemplate, PartParameter +from .models import PartTestTemplate from common.models import Currency @@ -29,6 +30,19 @@ class PartImageForm(HelperForm): ] +class EditPartTestTemplateForm(HelperForm): + """ Class for creating / editing a PartTestTemplate object """ + + class Meta: + model = PartTestTemplate + + fields = [ + 'part', + 'test_name', + 'required' + ] + + class BomExportForm(forms.Form): """ Simple form to let user set BOM export options, before exporting a BOM (bill of materials) file. diff --git a/InvenTree/part/templates/part/part_tests.html b/InvenTree/part/templates/part/part_tests.html index 0d6fb56668..5728f2205e 100644 --- a/InvenTree/part/templates/part/part_tests.html +++ b/InvenTree/part/templates/part/part_tests.html @@ -36,4 +36,40 @@ loadPartTestTemplateTable( } ); +function reloadTable() { + $("#test-template-table").bootstrapTable("refresh"); +} + +$("#add-test-template").click(function() { + launchModalForm( + "{% url 'part-test-template-create' %}", + { + data: { + part: {{ part.id }}, + }, + success: reloadTable, + } + ); +}); + +$("#test-template-table").on('click', '.button-test-edit', function() { + var button = $(this); + + var url = `/part/test-template/${button.attr('pk')}/edit/`; + + launchModalForm(url, { + success: reloadTable, + }); +}); + +$("#test-template-table").on('click', '.button-test-delete', function() { + var button = $(this); + + var url = `/part/test-template/${button.attr('pk')}/delete/`; + + launchModalForm(url, { + success: reloadTable, + }); +}); + {% endblock %} \ No newline at end of file diff --git a/InvenTree/part/urls.py b/InvenTree/part/urls.py index a5aa412b24..7d5c279e75 100644 --- a/InvenTree/part/urls.py +++ b/InvenTree/part/urls.py @@ -108,6 +108,13 @@ part_urls = [ # Part attachments url(r'^attachment/', include(part_attachment_urls)), + # Part test templates + url(r'^test-template/', include([ + url(r'^new/', views.PartTestTemplateCreate.as_view(), name='part-test-template-create'), + url(r'^(?P\d+)/edit/', views.PartTestTemplateEdit.as_view(), name='part-test-template-edit'), + url(r'^(?P\d+)/delete/', views.PartTestTemplateDelete.as_view(), name='part-test-template-delete'), + ])), + # Part parameters url(r'^parameter/', include(part_parameter_urls)), diff --git a/InvenTree/part/views.py b/InvenTree/part/views.py index ce2fc415be..c81df31484 100644 --- a/InvenTree/part/views.py +++ b/InvenTree/part/views.py @@ -25,6 +25,7 @@ from .models import PartCategory, Part, PartAttachment from .models import PartParameterTemplate, PartParameter from .models import BomItem from .models import match_part_names +from .models import PartTestTemplate from common.models import Currency, InvenTreeSetting from company.models import SupplierPart @@ -149,6 +150,55 @@ class PartAttachmentDelete(AjaxDeleteView): } +class PartTestTemplateCreate(AjaxCreateView): + """ View for creating a PartTestTemplate """ + + model = PartTestTemplate + form_class = part_forms.EditPartTestTemplateForm + ajax_form_title = _("Create Test Template") + + def get_initial(self): + + initials = super().get_initial() + + try: + part_id = self.request.GET.get('part', None) + initials['part'] = Part.objects.get(pk=part_id) + except (ValueError, Part.DoesNotExist): + pass + + return initials + + def get_form(self): + + form = super().get_form() + form.fields['part'].widget = HiddenInput() + + return form + + +class PartTestTemplateEdit(AjaxUpdateView): + """ View for editing a PartTestTemplate """ + + model = PartTestTemplate + form_class = part_forms.EditPartTestTemplateForm + ajax_form_title = _("Edit Test Template") + + def get_form(self): + + form = super().get_form() + form.fields['part'].widget = HiddenInput() + + return form + + +class PartTestTemplateDelete(AjaxDeleteView): + """ View for deleting a PartTestTemplate """ + + model = PartTestTemplate + ajax_form_title = _("Delete Test Template") + + class PartSetCategory(AjaxUpdateView): """ View for settings the part category for multiple parts at once """