diff --git a/InvenTree/templates/js/bom.html b/InvenTree/templates/js/bom.html index 1d75124c39..ceb8977c04 100644 --- a/InvenTree/templates/js/bom.html +++ b/InvenTree/templates/js/bom.html @@ -280,48 +280,34 @@ function loadBomTable(table, options) { params.sub_part_detail = true; } - function requestBomItems() { + function requestSubItems(part_pk) { - var data = table.bootstrapTable('getData'); - - for (var idx = 0; idx < data.length; idx++) { - var row = data[idx]; - - if (row.sub_part_detail.assembly && !row.requested) { - - row.requested = true; - - // Mark this row as 'requested' so it doesn't get updated again - table.bootstrapTable('updateRow', idx, row, true); - - inventreeGet( - options.bom_url, - { - part: row.sub_part, - sub_part_detail: true, - }, - { - success: function(response) { - - // Add the data to the table - table.bootstrapTable('append', response); - - // Request any NEW sub BOMs - requestBomItems(); - }, - error: function() { - console.log('Error requesting BOM for part=' + row.sub_part); - } + inventreeGet( + options.bom_url, + { + part: part_pk, + sub_part_detail: true, + }, + { + success: function(response) { + for (var idx = 0; idx < response.length; idx++) { + response[idx].parentId = part_pk; } - ); + + table.bootstrapTable('append', response); + }, + error: function() { + console.log('Error requesting BOM for part=' + part_pk); + } } - } + ) } table.bootstrapTable({ treeEnable: true, rootParentId: options.parent_id, idField: 'sub_part', + uniqueId: 'pk', parentIdField: 'part', treeShowField: 'sub_part', sortable: true, @@ -347,7 +333,28 @@ function loadBomTable(table, options) { } }); }, - onLoadSuccess: requestBomItems, + onLoadSuccess: function() { + + var data = table.bootstrapTable('getData'); + + for (var idx = 0; idx < data.length; idx++) { + var row = data[idx]; + + // If a row already has a parent ID set, it's already been updated! + if (row.parentId) { + continue; + } + + // Set the parent ID of the top-level rows + row.parentId = options.parent_id; + + table.bootstrapTable('updateRow', idx, row, true); + + if (row.sub_part_detail.assembly) { + requestSubItems(row.sub_part); + } + } + }, }); // In editing mode, attached editables to the appropriate table elements