From d9350877c6d911335664d11d5f1c2bb6c558cc67 Mon Sep 17 00:00:00 2001 From: Oliver Date: Wed, 17 Aug 2022 14:38:37 +1000 Subject: [PATCH] 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. --- InvenTree/templates/js/translated/part.js | 66 +++++++++++------------ 1 file changed, 31 insertions(+), 35 deletions(-) diff --git a/InvenTree/templates/js/translated/part.js b/InvenTree/templates/js/translated/part.js index d0ade1dd44..cbb7c77c28 100644 --- a/InvenTree/templates/js/translated/part.js +++ b/InvenTree/templates/js/translated/part.js @@ -1460,46 +1460,42 @@ function loadPartTable(table, url, options={}) { title: '{% trans "Stock" %}', searchable: false, formatter: function(value, row) { - var link = '?display=part-stock'; - if (row.in_stock) { - // There IS stock available for this part + var text = ''; - // Is stock "low" (below the 'minimum_stock' quantity)? - if (row.minimum_stock && row.minimum_stock > row.in_stock) { - value += `{% trans "Low stock" %}`; - } else if (value == 0) { - if (row.ordering) { - // There is no available stock, but stock is on order - value = `0{% trans "On Order" %}: ${row.ordering}`; - link = '?display=purchase-orders'; - } else if (row.building) { - // There is no available stock, but stock is being built - value = `0{% trans "Building" %}: ${row.building}`; - link = '?display=build-orders'; - } else { - // There is no available stock - value = `0{% trans "No stock available" %}`; - } - } + if (row.unallocated_stock != row.in_stock) { + text = `${row.unallocated_stock} / ${row.in_stock}`; } else { - // There IS NO stock available for this part - - if (row.ordering) { - // There is no stock, but stock is on order - value = `0{% trans "On Order" %}: ${row.ordering}`; - link = '?display=purchase-orders'; - } else if (row.building) { - // There is no stock, but stock is being built - value = `0{% trans "Building" %}: ${row.building}`; - link = '?display=build-orders'; - } else { - // There is no stock - value = `0{% trans "No Stock" %}`; - } + text = `${row.in_stock}`; } - return renderLink(value, `/part/${row.pk}/${link}`); + // Construct extra informational badges + var badges = ''; + + if (row.in_stock == 0) { + badges += ``; + } else if (row.in_stock < row.minimum_stock) { + badges += ``; + } + + if (row.ordering && row.ordering > 0) { + badges += renderLink( + ``, + `/part/${row.pk}/?display=purchase-orders` + ); + } + + if (row.building && row.building > 0) { + badges += renderLink( + ``, + `/part/${row.pk}/?display=build-orders` + ); + } + + text = renderLink(text, `/part/${row.pk}/?display=part-stock`); + text += badges; + + return text; } };