mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Merge pull request #987 from SchrodingersGat/serial_number_filter
Stock Search
This commit is contained in:
commit
d6bca4d6ca
@ -440,6 +440,8 @@ class StockList(generics.ListCreateAPIView):
|
|||||||
|
|
||||||
params = self.request.query_params
|
params = self.request.query_params
|
||||||
|
|
||||||
|
queryset = super().filter_queryset(queryset)
|
||||||
|
|
||||||
# Perform basic filtering:
|
# Perform basic filtering:
|
||||||
# Note: We do not let DRF filter here, it be slow AF
|
# Note: We do not let DRF filter here, it be slow AF
|
||||||
|
|
||||||
@ -680,6 +682,14 @@ class StockList(generics.ListCreateAPIView):
|
|||||||
filter_fields = [
|
filter_fields = [
|
||||||
]
|
]
|
||||||
|
|
||||||
|
search_fields = [
|
||||||
|
'serial',
|
||||||
|
'batch',
|
||||||
|
'part__name',
|
||||||
|
'part__IPN',
|
||||||
|
'part__description'
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
class StockAttachmentList(generics.ListCreateAPIView, AttachmentMixin):
|
class StockAttachmentList(generics.ListCreateAPIView, AttachmentMixin):
|
||||||
"""
|
"""
|
||||||
|
@ -32,6 +32,8 @@ InvenTree | {% trans "Search Results" %}
|
|||||||
|
|
||||||
{% include "InvenTree/search_stock_location.html" with collapse_id="locations" %}
|
{% include "InvenTree/search_stock_location.html" with collapse_id="locations" %}
|
||||||
|
|
||||||
|
{% include "InvenTree/search_stock_items.html" with collapse_id="stock" %}
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block js_load %}
|
{% block js_load %}
|
||||||
@ -42,9 +44,8 @@ InvenTree | {% trans "Search Results" %}
|
|||||||
{% block js_ready %}
|
{% block js_ready %}
|
||||||
{{ block.super }}
|
{{ block.super }}
|
||||||
|
|
||||||
$(".panel-group").hide();
|
|
||||||
|
|
||||||
function onSearchResults(table, output) {
|
function onSearchResults(table, output) {
|
||||||
|
|
||||||
$(table).on('load-success.bs.table', function() {
|
$(table).on('load-success.bs.table', function() {
|
||||||
|
|
||||||
var panel = $(output).closest('.panel-group');
|
var panel = $(output).closest('.panel-group');
|
||||||
@ -56,7 +57,6 @@ InvenTree | {% trans "Search Results" %}
|
|||||||
text = '<i>No results</i>'
|
text = '<i>No results</i>'
|
||||||
|
|
||||||
$(panel).hide();
|
$(panel).hide();
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
text = n + ' result';
|
text = n + ' result';
|
||||||
@ -67,17 +67,23 @@ InvenTree | {% trans "Search Results" %}
|
|||||||
|
|
||||||
$(panel).show();
|
$(panel).show();
|
||||||
|
|
||||||
|
var collapse = panel.find('.panel-collapse');
|
||||||
|
|
||||||
|
collapse.collapse('show');
|
||||||
|
|
||||||
$("#no-search-results").hide();
|
$("#no-search-results").hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
$(output).html(text);
|
$(output).html(`<i>${text}</i>`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
onSearchResults("#category-results-table", "#category-results-count");
|
onSearchResults("#category-results-table", "#category-results-count");
|
||||||
|
|
||||||
onSearchResults("#location-results-table", "#location-results-count");
|
onSearchResults("#location-results-table", "#location-results-count");
|
||||||
|
|
||||||
|
onSearchResults("#stock-results-table", "#stock-results-count");
|
||||||
|
|
||||||
onSearchResults('#part-results-table', '#part-result-count');
|
onSearchResults('#part-results-table', '#part-result-count');
|
||||||
|
|
||||||
onSearchResults('#company-results-table', '#company-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({
|
$("#location-results-table").inventreeTable({
|
||||||
url: "{% url 'api-location-list' %}",
|
url: "{% url 'api-location-list' %}",
|
||||||
|
16
InvenTree/templates/InvenTree/search_stock_items.html
Normal file
16
InvenTree/templates/InvenTree/search_stock_items.html
Normal 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 %}
|
@ -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>
|
||||||
|
Loading…
Reference in New Issue
Block a user