Merge pull request #987 from SchrodingersGat/serial_number_filter

Stock Search
This commit is contained in:
Oliver 2020-09-19 23:48:11 +10:00 committed by GitHub
commit d6bca4d6ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 119 additions and 6 deletions

View File

@ -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,14 @@ class StockList(generics.ListCreateAPIView):
filter_fields = [
]
search_fields = [
'serial',
'batch',
'part__name',
'part__IPN',
'part__description'
]
class StockAttachmentList(generics.ListCreateAPIView, AttachmentMixin):
"""

View File

@ -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 = '<i>No results</i>'
$(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(`<i>${text}</i>`);
});
}
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 '<i>{% trans "No stock location set" %}</i>';
}
}
}
},
]
});
$("#location-results-table").inventreeTable({
url: "{% url 'api-location-list' %}",

View File

@ -0,0 +1,16 @@
{% extends "collapse.html" %}
{% load i18n %}
{% block collapse_title %}
<h4>{% trans "Stock Items" %}</h4>
{% endblock %}
{% block collapse_heading %}
<h4><span id='stock-results-count'>{% include "InvenTree/searching.html" %}</span></h4>
{% endblock %}
{% block collapse_content %}
<table class='table table-striped table-condensed' data-toolbar="#button-toolbar" id='stock-results-table'>
</table>
{% endblock %}

View File

@ -1 +1,3 @@
<span class='glyphicon glyphicon-refresh glyphicon-refresh-animate'></span> Searching
{% load i18n %}
<span class='fas fa-spin fa-hourglass-half'></span> <i>{% trans "Searching" %}</i>