Merge pull request #682 from SchrodingersGat/low-stock

"Low Stock" badge
This commit is contained in:
Oliver 2020-03-30 15:35:53 +11:00 committed by GitHub
commit e28fe6df6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 27 additions and 10 deletions

View File

@ -112,6 +112,10 @@
font-size: 100%;
}
.label-right {
float: right;
}
/* Bootstrap table overrides */
.stock-sub-group td {

View File

@ -182,25 +182,27 @@ function loadPartTable(table, url, options={}) {
searchable: false,
sortable: true,
formatter: function(value, row, index, field) {
var html = "";
var link = "stock";
if (value) {
// There IS stock available for this part
if (row.units) {
value += ' <i><small>' + row.units + '</small></i>';
// Is stock "low" (below the 'minimum_stock' quantity)?
if (row.minimum_stock && row.minimum_stock > value) {
value += "<span class='label label-right label-warning'>Low stock</span>";
}
html = value;
} else if (row.on_order) {
value = "<span class='label label-primary'>On Order : " + row.on_order + "</span>";
// There is no stock available, but stock is on order
value = "0<span class='label label-right label-primary'>On Order : " + row.on_order + "</span>";
link = "orders";
} else if (row.building) {
value = "<span class='label label-info'>Building : " + row.building + "</span>";
// There is no stock available, but stock is being built
value = "0<span class='label label-right label-info'>Building : " + row.building + "</span>";
link = "builds";
} else {
value ="<span class='label label-warning'>No Stock</span>";
// There is no stock available
value = "0<span class='label label-right label-danger'>No Stock</span>";
}
return renderLink(value, '/part/' + row.pk + "/" + link + "/");

View File

@ -178,6 +178,7 @@ class PartList(generics.ListCreateAPIView):
'is_template',
'URL',
'units',
'minimum_stock',
'trackable',
'assembly',
'component',

View File

@ -98,7 +98,7 @@
</tr>
<tr>
<td>{% trans "In Stock" %}</td>
<td>{% decimal part.total_stock %}</td>
<td>{% include "part/stock_count.html" %}</td>
</tr>
{% if not part.is_template %}
{% if part.allocation_count > 0 %}

View File

@ -0,0 +1,10 @@
{% load inventree_extras %}
{% load i18n %}
{% decimal part.total_stock %}
{% if part.total_stock == 0 %}
<span class='label label-danger'>{% trans "No Stock" %}</span>
{% elif part.total_stock < part.minimum_stock %}
<span class='label label-warning'>{% trans "Low Stock" %}</span>
{% endif %}