Update 'stock' icons for part table (#3561)

- Display on-order and building quantity as icons
- Simplified display logic
- Do not hide information in certain circumstances.
This commit is contained in:
Oliver 2022-08-17 14:38:37 +10:00 committed by GitHub
parent 0a57f9d459
commit d9350877c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1460,46 +1460,42 @@ function loadPartTable(table, url, options={}) {
title: '{% trans "Stock" %}', title: '{% trans "Stock" %}',
searchable: false, searchable: false,
formatter: function(value, row) { formatter: function(value, row) {
var link = '?display=part-stock';
if (row.in_stock) { var text = '';
// There IS stock available for this part
// Is stock "low" (below the 'minimum_stock' quantity)? if (row.unallocated_stock != row.in_stock) {
if (row.minimum_stock && row.minimum_stock > row.in_stock) { text = `${row.unallocated_stock} / ${row.in_stock}`;
value += `<span class='badge badge-right rounded-pill bg-warning'>{% trans "Low stock" %}</span>`;
} else if (value == 0) {
if (row.ordering) {
// There is no available stock, but stock is on order
value = `0<span class='badge badge-right rounded-pill bg-info'>{% trans "On Order" %}: ${row.ordering}</span>`;
link = '?display=purchase-orders';
} else if (row.building) {
// There is no available stock, but stock is being built
value = `0<span class='badge badge-right rounded-pill bg-info'>{% trans "Building" %}: ${row.building}</span>`;
link = '?display=build-orders';
} else {
// There is no available stock
value = `0<span class='badge badge-right rounded-pill bg-warning'>{% trans "No stock available" %}</span>`;
}
}
} else { } else {
// There IS NO stock available for this part text = `${row.in_stock}`;
if (row.ordering) {
// There is no stock, but stock is on order
value = `0<span class='badge badge-right rounded-pill bg-info'>{% trans "On Order" %}: ${row.ordering}</span>`;
link = '?display=purchase-orders';
} else if (row.building) {
// There is no stock, but stock is being built
value = `0<span class='badge badge-right rounded-pill bg-info'>{% trans "Building" %}: ${row.building}</span>`;
link = '?display=build-orders';
} else {
// There is no stock
value = `0<span class='badge badge-right rounded-pill bg-danger'>{% trans "No Stock" %}</span>`;
}
} }
return renderLink(value, `/part/${row.pk}/${link}`); // Construct extra informational badges
var badges = '';
if (row.in_stock == 0) {
badges += `<span class='fas fa-exclamation-circle icon-red float-right' title='{% trans "No stock" %}'></span>`;
} else if (row.in_stock < row.minimum_stock) {
badges += `<span class='fas fa-exclamation-circle icon-yellow float-right' title='{% trans "Low stock" %}'></span>`;
}
if (row.ordering && row.ordering > 0) {
badges += renderLink(
`<span class='fas fa-shopping-cart float-right' title='{% trans "On Order" %}: ${row.ordering}'></span>`,
`/part/${row.pk}/?display=purchase-orders`
);
}
if (row.building && row.building > 0) {
badges += renderLink(
`<span class='fas fa-tools float-right' title='{% trans "Building" %}: ${row.building}'></span>`,
`/part/${row.pk}/?display=build-orders`
);
}
text = renderLink(text, `/part/${row.pk}/?display=part-stock`);
text += badges;
return text;
} }
}; };