From 083bfe05c0b11e120f21fea3d19f592295fc9757 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sat, 19 Sep 2020 21:49:07 +1000 Subject: [PATCH 1/3] Add ability to search stock API - serial number - part information --- InvenTree/stock/api.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/InvenTree/stock/api.py b/InvenTree/stock/api.py index 7741c67129..ad2c46e8f3 100644 --- a/InvenTree/stock/api.py +++ b/InvenTree/stock/api.py @@ -440,6 +440,8 @@ class StockList(generics.ListCreateAPIView): params = self.request.query_params + queryset = super().filter_queryset(queryset) + # Perform basic filtering: # Note: We do not let DRF filter here, it be slow AF @@ -680,6 +682,13 @@ class StockList(generics.ListCreateAPIView): filter_fields = [ ] + search_fields = [ + 'serial', + 'part__name', + 'part__IPN', + 'part__description' + ] + class StockAttachmentList(generics.ListCreateAPIView, AttachmentMixin): """ From 89b3290068d0c91818419ee17103b9273ef00141 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sat, 19 Sep 2020 23:38:33 +1000 Subject: [PATCH 2/3] Add search results for stock items --- InvenTree/templates/InvenTree/search.html | 95 ++++++++++++++++++- .../InvenTree/search_stock_items.html | 16 ++++ InvenTree/templates/InvenTree/searching.html | 4 +- 3 files changed, 109 insertions(+), 6 deletions(-) create mode 100644 InvenTree/templates/InvenTree/search_stock_items.html diff --git a/InvenTree/templates/InvenTree/search.html b/InvenTree/templates/InvenTree/search.html index 76fd62b697..c030fb42a7 100644 --- a/InvenTree/templates/InvenTree/search.html +++ b/InvenTree/templates/InvenTree/search.html @@ -32,6 +32,8 @@ InvenTree | {% trans "Search Results" %} {% include "InvenTree/search_stock_location.html" with collapse_id="locations" %} +{% include "InvenTree/search_stock_items.html" with collapse_id="stock" %} + {% endblock %} {% block js_load %} @@ -42,9 +44,8 @@ InvenTree | {% trans "Search Results" %} {% block js_ready %} {{ block.super }} - $(".panel-group").hide(); - function onSearchResults(table, output) { + $(table).on('load-success.bs.table', function() { var panel = $(output).closest('.panel-group'); @@ -56,7 +57,6 @@ InvenTree | {% trans "Search Results" %} text = 'No results' $(panel).hide(); - } else { text = n + ' result'; @@ -67,17 +67,23 @@ InvenTree | {% trans "Search Results" %} $(panel).show(); + var collapse = panel.find('.panel-collapse'); + + collapse.collapse('show'); + $("#no-search-results").hide(); } - $(output).html(text); + $(output).html(`${text}`); }); } onSearchResults("#category-results-table", "#category-results-count"); onSearchResults("#location-results-table", "#location-results-count"); - + + onSearchResults("#stock-results-table", "#stock-results-count"); + onSearchResults('#part-results-table', '#part-result-count'); onSearchResults('#company-results-table', '#company-result-count'); @@ -104,6 +110,85 @@ InvenTree | {% trans "Search Results" %} ], }); + $('#stock-results-table').inventreeTable({ + url: "{% url 'api-stock-list' %}", + queryParams: { + search: "{{ query }}", + part_detail: true, + location_detail: true, + }, + columns: [ + { + field: 'part', + title: "{% trans "Part" %}", + sortable: true, + formatter: function(value, row) { + var url = `/stock/item/${row.pk}/`; + var thumb = row.part_detail.thumbnail; + var name = row.part_detail.full_name; + + html = imageHoverIcon(thumb) + renderLink(name, url); + + return html; + } + }, + { + field: 'part_description', + title: '{% trans "Description" %}', + sortable: true, + formatter: function(value, row, index, field) { + return row.part_detail.description; + } + }, + { + field: 'quantity', + title: '{% trans "Stock" %}', + sortable: true, + formatter: function(value, row, index, field) { + + var val = parseFloat(value); + + // If there is a single unit with a serial number, use the serial number + if (row.serial && row.quantity == 1) { + val = '# ' + row.serial; + } else { + val = +val.toFixed(5); + } + + var html = renderLink(val, `/stock/item/${row.pk}/`); + + return html; + } + }, + { + field: 'status', + title: '{% trans "Status" %}', + sortable: 'true', + formatter: function(value, row, index, field) { + return stockStatusDisplay(value); + }, + }, + { + field: 'location_detail.pathstring', + title: '{% trans "Location" %}', + sortable: true, + formatter: function(value, row, index, field) { + if (value) { + return renderLink(value, `/stock/location/${row.location}/`); + } + else { + if (row.customer) { + var text = "{% trans "Shipped to customer" %}"; + return renderLink(text, `/company/${row.customer}/assigned-stock/`); + } else { + return '{% trans "No stock location set" %}'; + } + } + } + }, + ] + }); + $("#location-results-table").inventreeTable({ url: "{% url 'api-location-list' %}", diff --git a/InvenTree/templates/InvenTree/search_stock_items.html b/InvenTree/templates/InvenTree/search_stock_items.html new file mode 100644 index 0000000000..16d1542d96 --- /dev/null +++ b/InvenTree/templates/InvenTree/search_stock_items.html @@ -0,0 +1,16 @@ +{% extends "collapse.html" %} + +{% load i18n %} + +{% block collapse_title %} +

{% trans "Stock Items" %}

+{% endblock %} + +{% block collapse_heading %} +

{% include "InvenTree/searching.html" %}

+{% endblock %} + +{% block collapse_content %} + +
+{% endblock %} \ No newline at end of file diff --git a/InvenTree/templates/InvenTree/searching.html b/InvenTree/templates/InvenTree/searching.html index 5821515ad7..cb33727a9e 100644 --- a/InvenTree/templates/InvenTree/searching.html +++ b/InvenTree/templates/InvenTree/searching.html @@ -1 +1,3 @@ - Searching \ No newline at end of file +{% load i18n %} + + {% trans "Searching" %} From f19a727a02a5e37af5bf28934cdf34857a88e4a9 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sat, 19 Sep 2020 23:40:06 +1000 Subject: [PATCH 3/3] Allow searching by stock item batch code --- InvenTree/stock/api.py | 1 + 1 file changed, 1 insertion(+) diff --git a/InvenTree/stock/api.py b/InvenTree/stock/api.py index ad2c46e8f3..54cb5a62cf 100644 --- a/InvenTree/stock/api.py +++ b/InvenTree/stock/api.py @@ -684,6 +684,7 @@ class StockList(generics.ListCreateAPIView): search_fields = [ 'serial', + 'batch', 'part__name', 'part__IPN', 'part__description'