From ade5a81a1ab7f012b0ee85f624a2313b93a03c73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A1lm=C3=A1n=20R=C3=B3zsahegyi?= Date: Sat, 2 Apr 2022 16:25:42 +0200 Subject: [PATCH] Enhance partStockLabel with ordering/building quantites --- InvenTree/templates/js/translated/part.js | 34 ++++++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/InvenTree/templates/js/translated/part.js b/InvenTree/templates/js/translated/part.js index 1c6bd56d90..1c66c32b6e 100644 --- a/InvenTree/templates/js/translated/part.js +++ b/InvenTree/templates/js/translated/part.js @@ -494,14 +494,40 @@ function duplicateBom(part_id, options={}) { function partStockLabel(part, options={}) { if (part.in_stock) { - if (part.unallocated_stock) { - return `{% trans "Available" %}: ${part.unallocated_stock}/${part.in_stock}`; + // There IS stock available for this part + + // Is stock "low" (below the 'minimum_stock' quantity)? + if (part.minimum_stock && part.minimum_stock > part.in_stock) { + return `{% trans "Low stock" %}: ${part.in_stock}${part.units}`; + } else if (part.unallocated_stock == 0) { + if (part.ordering) { + // There is no available stock, but stock is on order + return `{% trans "On Order" %}: ${part.ordering}${part.units}`; + } else if (part.building) { + // There is no available stock, but stock is being built + return `{% trans "Building" %}: ${part.building}${part.units}`; + } else { + // There is no available stock + return `{% trans "Available" %}: 0/${part.in_stock}${part.units}`; + } } else { - return `{% trans "Available" %}: ${part.unallocated_stock}/${part.in_stock}`; + return `{% trans "Available" %}: ${part.unallocated_stock}/${part.in_stock}${part.units}`; } } else { - return `{% trans "No Stock" %}`; + // There IS NO stock available for this part + + if (part.ordering) { + // There is no stock, but stock is on order + return `{% trans "On Order" %}: ${part.ordering}${part.units}`; + } else if (part.building) { + // There is no stock, but stock is being built + return `{% trans "Building" %}: ${part.building}${part.units}`; + } else { + // There is no stock + return `{% trans "No Stock" %}`; + } } + }