From d45994794981682064a1c6d5f7a05965f36c7733 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Thu, 14 Jan 2021 13:34:51 +1100 Subject: [PATCH] Add "Can Build" column in BOM view --- InvenTree/templates/js/bom.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/InvenTree/templates/js/bom.js b/InvenTree/templates/js/bom.js index 299045cfa5..e1b3b46cc0 100644 --- a/InvenTree/templates/js/bom.js +++ b/InvenTree/templates/js/bom.js @@ -255,6 +255,38 @@ function loadBomTable(table, options) { }); */ } + + cols.push( + { + 'field': 'can_build', + 'title': '{% trans "Can Build" %}', + formatter: function(value, row, index, field) { + var can_build = 0; + + if (row.quantity > 0) { + can_build = row.sub_part_detail.stock / row.quantity; + } + + return +can_build.toFixed(2); + }, + sorter: function(valA, valB, rowA, rowB) { + // Function to sort the "can build" quantity + var cb_a = 0; + var cb_b = 0; + + if (rowA.quantity > 0) { + cb_a = rowA.sub_part_detail.stock / rowA.quantity; + } + + if (rowB.quantity > 0) { + cb_b = rowB.sub_part_detail.stock / rowB.quantity; + } + + return (cb_a > cb_b) ? 1 : -1; + }, + sortable: true, + } + ) // Part notes cols.push(