mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Re-enable display of multi-level BOM
This commit is contained in:
parent
55d09c4469
commit
fb4e44b73f
@ -671,9 +671,7 @@ function loadBomTable(table, options={}) {
|
|||||||
// Do we show part pricing in the BOM table?
|
// Do we show part pricing in the BOM table?
|
||||||
var show_pricing = global_settings.PART_SHOW_PRICE_IN_BOM;
|
var show_pricing = global_settings.PART_SHOW_PRICE_IN_BOM;
|
||||||
|
|
||||||
if (!show_pricing) {
|
params.include_pricing = show_pricing == true;
|
||||||
params.include_pricing = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options.part_detail) {
|
if (options.part_detail) {
|
||||||
params.part_detail = true;
|
params.part_detail = true;
|
||||||
@ -989,32 +987,40 @@ function loadBomTable(table, options={}) {
|
|||||||
|
|
||||||
// Function to request BOM data for sub-items
|
// Function to request BOM data for sub-items
|
||||||
// This function may be called recursively for multi-level BOMs
|
// This function may be called recursively for multi-level BOMs
|
||||||
function requestSubItems(bom_pk, part_pk) {
|
function requestSubItems(bom_pk, part_pk, depth=0) {
|
||||||
|
|
||||||
// TODO: 2022-02-03 Currently, multi-level BOMs are not actually displayed.
|
// Prevent multi-level recursion
|
||||||
|
const MAX_BOM_DEPTH = 25;
|
||||||
|
|
||||||
// Re-enable this function once multi-level display has been re-deployed
|
if (depth >= MAX_BOM_DEPTH) {
|
||||||
return;
|
console.log(`Maximum BOM depth (${MAX_BOM_DEPTH}) reached!`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
inventreeGet(
|
inventreeGet(
|
||||||
options.bom_url,
|
options.bom_url,
|
||||||
{
|
{
|
||||||
part: part_pk,
|
part: part_pk,
|
||||||
sub_part_detail: true,
|
sub_part_detail: true,
|
||||||
|
include_pricing: show_pricing == true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
success: function(response) {
|
success: function(response) {
|
||||||
|
|
||||||
|
// Add the returned sub-items to the table
|
||||||
for (var idx = 0; idx < response.length; idx++) {
|
for (var idx = 0; idx < response.length; idx++) {
|
||||||
|
|
||||||
response[idx].parentId = bom_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.bootstrapTable('append', response);
|
||||||
|
|
||||||
|
// Next, re-iterate and check if the new items also have sub items
|
||||||
|
response.forEach(function(bom_item) {
|
||||||
|
if (bom_item.sub_part_detail.assembly) {
|
||||||
|
requestSubItems(bom_item.pk, bom_item.sub_part, depth + 1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
table.treegrid('collapseAll');
|
table.treegrid('collapseAll');
|
||||||
},
|
},
|
||||||
error: function(xhr) {
|
error: function(xhr) {
|
||||||
@ -1026,7 +1032,7 @@ function loadBomTable(table, options={}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
table.inventreeTable({
|
table.inventreeTable({
|
||||||
treeEnable: !options.editable,
|
treeEnable: true,
|
||||||
rootParentId: parent_id,
|
rootParentId: parent_id,
|
||||||
idField: 'pk',
|
idField: 'pk',
|
||||||
uniqueId: 'pk',
|
uniqueId: 'pk',
|
||||||
@ -1066,38 +1072,37 @@ function loadBomTable(table, options={}) {
|
|||||||
url: options.bom_url,
|
url: options.bom_url,
|
||||||
onPostBody: function() {
|
onPostBody: function() {
|
||||||
|
|
||||||
if (!options.editable) {
|
table.treegrid({
|
||||||
table.treegrid({
|
treeColumn: 1,
|
||||||
treeColumn: 0,
|
onExpand: function() {
|
||||||
onExpand: function() {
|
}
|
||||||
}
|
});
|
||||||
});
|
|
||||||
}
|
table.treegrid('collapseAll');
|
||||||
},
|
},
|
||||||
onLoadSuccess: function() {
|
onLoadSuccess: function() {
|
||||||
|
|
||||||
if (options.editable) {
|
if (options.editable) {
|
||||||
table.bootstrapTable('uncheckAll');
|
table.bootstrapTable('uncheckAll');
|
||||||
} else {
|
}
|
||||||
|
|
||||||
var data = table.bootstrapTable('getData');
|
var data = table.bootstrapTable('getData');
|
||||||
|
|
||||||
for (var idx = 0; idx < data.length; idx++) {
|
for (var idx = 0; idx < data.length; idx++) {
|
||||||
var row = data[idx];
|
var row = data[idx];
|
||||||
|
|
||||||
// If a row already has a parent ID set, it's already been updated!
|
// If a row already has a parent ID set, it's already been updated!
|
||||||
if (row.parentId) {
|
if (row.parentId) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the parent ID of the top-level rows
|
// Set the parent ID of the top-level rows
|
||||||
row.parentId = parent_id;
|
row.parentId = parent_id;
|
||||||
|
|
||||||
table.bootstrapTable('updateRow', idx, row, true);
|
table.bootstrapTable('updateRow', idx, row, true);
|
||||||
|
|
||||||
if (row.sub_part_detail.assembly) {
|
if (row.sub_part_detail.assembly) {
|
||||||
requestSubItems(row.pk, row.sub_part);
|
requestSubItems(row.pk, row.sub_part);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user