From eba0d15fe4998fd4ac1c02c8fed7fa46597b5ef9 Mon Sep 17 00:00:00 2001 From: Oliver Date: Mon, 4 Oct 2021 16:11:15 +1100 Subject: [PATCH] Rough layout of javascript function - allocateStockToBuild - provide build ID and part ID - optionally provide output ID - optionally provide list of part ID to filter against --- InvenTree/templates/js/translated/build.js | 59 +++++++++++++++++++++- 1 file changed, 57 insertions(+), 2 deletions(-) diff --git a/InvenTree/templates/js/translated/build.js b/InvenTree/templates/js/translated/build.js index d359d6cf4e..c28a926e19 100644 --- a/InvenTree/templates/js/translated/build.js +++ b/InvenTree/templates/js/translated/build.js @@ -694,8 +694,9 @@ function loadBuildOutputAllocationTable(buildInfo, output, options={}) { }, columns: [ { - field: 'pk', - visible: false, + visible: true, + switchable: false, + checkbox: true, }, { field: 'sub_part_detail.full_name', @@ -817,6 +818,60 @@ function loadBuildOutputAllocationTable(buildInfo, output, options={}) { } + +/** + * Allocate stock items to a build + * + * arguments: + * - buildId: ID / PK value for the build + * - partId: ID / PK value for the part being built + * + * options: + * - outputId: ID / PK of the associated build output (or null for untracked items) + * - parts: List of ID values for filtering against specific sub parts + */ +function allocateStockToBuild(buildId, partId, options={}) { + + // ID of the associated "build output" (or null) + var outputId = options.output || null; + + // Extract list of BOM items (or empty list) + var subPartIds = options.parts || []; + + var bomItemQueryParams = { + part: partId, + sub_part_detail: true, + sub_part_trackable: outputId != null + }; + + inventreeGet( + '{% url "api-bom-list" %}', + bomItemQueryParams, + { + success: function(response) { + + // List of BOM item objects we are interested in + var bomItems = []; + + for (var idx = 0; idx < response.length; idx++) { + var item = response[idx]; + + var subPartId = item.sub_part; + + // Check if we are interested in this item + if (subPartIds.length > 0 && !subPartIds.includes(subPartId)) { + continue; + } + + bomItems.push(item); + } + } + } + ); +} + + + function loadBuildTable(table, options) { // Display a table of Build objects