mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Add search results for stock items
This commit is contained in:
parent
083bfe05c0
commit
89b3290068
@ -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');
|
||||
@ -57,7 +58,6 @@ InvenTree | {% trans "Search Results" %}
|
||||
|
||||
$(panel).hide();
|
||||
|
||||
|
||||
} else {
|
||||
text = n + ' result';
|
||||
|
||||
@ -67,10 +67,14 @@ 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>`);
|
||||
});
|
||||
}
|
||||
|
||||
@ -78,6 +82,8 @@ InvenTree | {% trans "Search Results" %}
|
||||
|
||||
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' %}",
|
||||
|
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