diff --git a/InvenTree/part/api.py b/InvenTree/part/api.py index c66e4c2696..1b672d4c68 100644 --- a/InvenTree/part/api.py +++ b/InvenTree/part/api.py @@ -149,6 +149,12 @@ class PartTestTemplateList(generics.ListCreateAPIView): except (ValueError, Part.DoesNotExist): pass + # Filter by 'required' status + required = params.get('required', None) + + if required is not None: + queryset = queryset.filter(required=required) + return queryset permission_classes = [permissions.IsAuthenticated] diff --git a/InvenTree/part/templates/part/part_tests.html b/InvenTree/part/templates/part/part_tests.html index bb0dbb7683..0d6fb56668 100644 --- a/InvenTree/part/templates/part/part_tests.html +++ b/InvenTree/part/templates/part/part_tests.html @@ -26,4 +26,14 @@ {% block js_ready %} {{ block.super }} +loadPartTestTemplateTable( + $("#test-template-table"), + { + part: {{ part.pk }}, + params: { + part: {{ part.pk }}, + } + } +); + {% endblock %} \ No newline at end of file diff --git a/InvenTree/templates/js/part.html b/InvenTree/templates/js/part.html index 57e7fa5798..528fc9aa93 100644 --- a/InvenTree/templates/js/part.html +++ b/InvenTree/templates/js/part.html @@ -284,4 +284,85 @@ function loadPartTable(table, url, options={}) { location.href = '/part/export/?parts=' + parts; }); -} \ No newline at end of file +} + + +function loadPartTestTemplateTable(table, options) { + /* + * Load PartTestTemplate table. + */ + + var params = options.params || {}; + + var part = options.part || null; + + var filterListElement = options.filterList || '#filter-list-parttests'; + + var filters = loadTableFilters("parttests"); + + var original = {}; + + for (var key in params) { + original[key] = params[key]; + } + + setupFilterList("parttests", table, filterListElement); + + // Override the default values, or add new ones + for (var key in params) { + filters[key] = params[key]; + } + + table.inventreeTable({ + method: 'get', + formatNoMatches: function() { + return '{% trans "No test templates matching query" %}'; + }, + url: "{% url 'api-part-test-template-list' %}", + queryParams: filters, + original: original, + columns: [ + { + field: 'pk', + title: 'ID', + visible: false, + }, + { + field: 'test_name', + title: "{% trans "Test Name" %}", + sortable: true, + }, + { + field: 'required', + title: "{% trans 'Required' %}", + sortable: true, + formatter: function(value) { + if (value) { + return `{% trans "YES" %}`; + } else { + return `{% trans "NO" %}`; + } + } + }, + { + field: 'buttons', + formatter: function(value, row) { + var pk = row.pk; + + if (row.part == part) { + var html = `