diff --git a/InvenTree/part/api.py b/InvenTree/part/api.py index d643b8671a..60c391c1e1 100644 --- a/InvenTree/part/api.py +++ b/InvenTree/part/api.py @@ -761,12 +761,26 @@ class BomList(generics.ListCreateAPIView): if sub_part is not None: queryset = queryset.filter(sub_part=sub_part) - # Filter by "trackable" status of the sub-part - trackable = params.get('trackable', None) + # Filter by "active" status of the part + part_active = params.get('part_active', None) - if trackable is not None: - trackable = str2bool(trackable) - queryset = queryset.filter(sub_part__trackable=trackable) + if part_active is not None: + part_active = str2bool(part_active) + queryset = queryset.filter(part__active=part_active) + + # Filter by "trackable" status of the part + part_trackable = params.get('part_trackable', None) + + if part_trackable is not None: + part_trackable = str2bool(part_trackable) + queryset = queryset.filter(part__trackable=part_trackable) + + # Filter by "trackable" status of the sub-part + sub_part_trackable = params.get('sub_part_trackable', None) + + if sub_part_trackable is not None: + sub_part_trackable = str2bool(sub_part_trackable) + queryset = queryset.filter(sub_part__trackable=sub_part_trackable) return queryset diff --git a/InvenTree/part/templates/part/bom.html b/InvenTree/part/templates/part/bom.html index c996edc2db..7b687f9aa0 100644 --- a/InvenTree/part/templates/part/bom.html +++ b/InvenTree/part/templates/part/bom.html @@ -32,21 +32,34 @@ {% endif %} -
- {% if editing_enabled %} - - - - - {% elif part.active %} - {% if roles.part.change %} - - {% if part.is_bom_valid == False %} - - {% endif %} - {% endif %} - - {% endif %} +
+
+ {% if editing_enabled %} + + + + + {% elif part.active %} + {% if roles.part.change %} + + {% if part.is_bom_valid == False %} + + {% endif %} + {% endif %} + + {% endif %} +
+
+ +
@@ -184,4 +197,4 @@ {% endif %} -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/InvenTree/part/templates/part/used_in.html b/InvenTree/part/templates/part/used_in.html index 3a6605847e..25e858b5f0 100644 --- a/InvenTree/part/templates/part/used_in.html +++ b/InvenTree/part/templates/part/used_in.html @@ -8,7 +8,13 @@
-
+
+
+ +
+
+ +
{% endblock %} @@ -16,52 +22,10 @@ {% block js_ready %} {{ block.super }} - $("#used-table").inventreeTable({ - formatNoMatches: function() { return "{{ part.full_name }} is not used to make any other parts"; }, - queryParams: function(p) { - return { - sub_part: {{ part.id }}, - part_detail: true, - } - }, - columns: [ - { - field: 'pk', - title: 'ID', - visible: false, - switchable: false, - }, - { - field: 'part_detail', - title: 'Part', - sortable: true, - formatter: function(value, row, index, field) { - var link = `/part/${value.pk}/bom/`; - var html = imageHoverIcon(row.part_detail.thumbnail) + renderLink(value.full_name, link); + loadUsedInTable('#used-table', { + part_detail: true, + part_id: {{ part.pk }} + }); - if (!row.part_detail.active) { - html += "{% trans "INACTIVE" %}"; - } - - return html; - } - }, - { - field: 'part_detail.description', - title: 'Description', - sortable: true, - }, - { - sortable: true, - field: 'quantity', - title: 'Uses', - formatter: function(value, row, index, field) { - return parseFloat(value); - }, - } - - ], - url: "{% url 'api-bom-list' %}" - }) {% endblock %} \ No newline at end of file diff --git a/InvenTree/templates/js/bom.html b/InvenTree/templates/js/bom.html index b804453ca2..59c7acbb7b 100644 --- a/InvenTree/templates/js/bom.html +++ b/InvenTree/templates/js/bom.html @@ -427,4 +427,86 @@ function loadBomTable(table, options) { ); }); } +} + +function loadUsedInTable(table, options) { + /* Load a table which displays all the parts that the given part is used in. + */ + + var params = { + sub_part: options.part_id, + ordering: 'name', + } + + if (options.part_detail) { + params.part_detail = true; + } + + if (options.sub_part_detail) { + params.sub_part_detail = true; + } + + var filters = {}; + + if (!options.disableFilters) { + filters = loadTableFilters("usedin"); + } + + for (var key in params) { + filters[key] = params[key]; + } + + setupFilterList("usedin", $(table)); + + // Columns to display in the table + var cols = [ + { + field: 'pk', + title: 'ID', + visible: false, + switchable: false, + }, + { + field: 'part_detail.full_name', + title: '{% trans "Part" %}', + sortable: true, + formatter: function(value, row, index, field) { + var link = `/part/${row.part}/bom/`; + var html = imageHoverIcon(row.part_detail.thumbnail) + renderLink(row.part_detail.full_name, link); + + if (!row.part_detail.active) { + html += "{% trans 'INACTIVE' %}"; + } + + return html; + } + }, + { + field: 'part_detail.description', + title: '{% trans "Description" %}', + sortable: true, + }, + { + sortable: true, + field: 'quantity', + title: '{% trans "Uses" %}', + formatter: function(value, row, index, field) { + return parseFloat(value); + }, + } + ]; + + // Load the table + $(table).inventreeTable({ + url: "{% url 'api-bom-list' %}", + formatNoMatches: function() { + return '{% trans "No matching parts found" %}'; + }, + columns: cols, + showColumns: true, + sortable: true, + serach: true, + queryParams: filters, + original: params, + }); } \ No newline at end of file diff --git a/InvenTree/templates/js/table_filters.html b/InvenTree/templates/js/table_filters.html index a97d358828..c05f01d37f 100644 --- a/InvenTree/templates/js/table_filters.html +++ b/InvenTree/templates/js/table_filters.html @@ -11,6 +11,30 @@ function getAvailableTableFilters(tableKey) { tableKey = tableKey.toLowerCase(); + // Filters for Bill of Materials table + if (tableKey == "bom") { + return { + sub_part_trackable: { + type: 'bool', + title: '{% trans "Trackable Part" %}' + }, + validated: { + type: 'bool', + title: '{% trans "Validated" %}', + }, + }; + } + + // Filters for the "used in" table + if (tableKey == 'usedin') { + return { + 'part_active': { + type: 'bool', + title: '{% trans "Active" %}', + }, + }; + } + // Filters for the "customer stock" table (really a subset of "stock") if (tableKey == "customerstock") { return {