From 41c4a5376bf9f278f02ea664e53b2781bab3039e Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Thu, 20 Aug 2020 08:52:22 +1000 Subject: [PATCH] Bugfix: Recursive BOM display - Actually request recursively! (duh) - Fix the idField and parentIdField for the BOM display (was incredibly wrong) - Sub-rows are initially displayed in the "collapsed" state --- InvenTree/templates/js/bom.html | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/InvenTree/templates/js/bom.html b/InvenTree/templates/js/bom.html index ceb8977c04..7692f28ba9 100644 --- a/InvenTree/templates/js/bom.html +++ b/InvenTree/templates/js/bom.html @@ -280,7 +280,9 @@ function loadBomTable(table, options) { params.sub_part_detail = true; } - function requestSubItems(part_pk) { + // Function to request BOM data for sub-items + // This function may be called recursively for multi-level BOMs + function requestSubItems(bom_pk, part_pk) { inventreeGet( options.bom_url, @@ -291,10 +293,17 @@ function loadBomTable(table, options) { { success: function(response) { for (var idx = 0; idx < response.length; idx++) { - response[idx].parentId = part_pk; + + response[idx].parentId = bom_pk; + + if (response[idx].sub_part_detail.assembly) { + requestSubItems(response[idx].pk, response[idx].sub_part) + } } table.bootstrapTable('append', response); + + table.treegrid('collapseAll'); }, error: function() { console.log('Error requesting BOM for part=' + part_pk); @@ -306,9 +315,9 @@ function loadBomTable(table, options) { table.bootstrapTable({ treeEnable: true, rootParentId: options.parent_id, - idField: 'sub_part', + idField: 'pk', uniqueId: 'pk', - parentIdField: 'part', + parentIdField: 'parentId', treeShowField: 'sub_part', sortable: true, search: true, @@ -351,7 +360,7 @@ function loadBomTable(table, options) { table.bootstrapTable('updateRow', idx, row, true); if (row.sub_part_detail.assembly) { - requestSubItems(row.sub_part); + requestSubItems(row.pk, row.sub_part); } } },