diff --git a/InvenTree/templates/js/translated/build.js b/InvenTree/templates/js/translated/build.js
index eb955d7ff0..a084b6ecb4 100644
--- a/InvenTree/templates/js/translated/build.js
+++ b/InvenTree/templates/js/translated/build.js
@@ -1031,6 +1031,23 @@ function loadBuildOutputAllocationTable(buildInfo, output, options={}) {
return row.required;
}
+ function availableQuantity(row) {
+
+ // Base stock
+ var available = row.available_stock;
+
+ // Substitute stock
+ available += (row.available_substitute_stock || 0);
+
+ // Variant stock
+ if (row.allow_variants) {
+ available += (row.available_variant_stock || 0);
+ }
+
+ return available;
+
+ }
+
function sumAllocations(row) {
// Calculat total allocations for a given row
if (!row.allocations) {
@@ -1429,12 +1446,13 @@ function loadBuildOutputAllocationTable(buildInfo, output, options={}) {
var url = `/part/${row.sub_part_detail.pk}/?display=part-stock`;
// Calculate total "available" (unallocated) quantity
- var base_stock = row.available_stock;
var substitute_stock = row.available_substitute_stock || 0;
var variant_stock = row.allow_variants ? (row.available_variant_stock || 0) : 0;
- var available_stock = base_stock + substitute_stock + variant_stock;
+ var available_stock = availableQuantity(row);
+ var required = requiredQuantity(row);
+
var text = `${available_stock}`;
if (available_stock <= 0) {
@@ -1453,9 +1471,19 @@ function loadBuildOutputAllocationTable(buildInfo, output, options={}) {
text += ``;
}
}
+
+ if (available_stock < required) {
+ text += ``;
+ } else {
+ text += ``;
+ }
return renderLink(text, url);
- }
+ },
+ sorter: function(valA, valB, rowA, rowB) {
+
+ return availableQuantity(rowA) > availableQuantity(rowB) ? 1 : -1;
+ },
},
{
field: 'allocated',