diff --git a/InvenTree/build/templates/build/detail.html b/InvenTree/build/templates/build/detail.html index 5e7f3d7c5f..2f707dcc40 100644 --- a/InvenTree/build/templates/build/detail.html +++ b/InvenTree/build/templates/build/detail.html @@ -317,6 +317,9 @@ var buildInfo = { quantity: {{ build.quantity }}, completed: {{ build.completed }}, part: {{ build.part.pk }}, + {% if build.take_from %} + source_location: {{ build.take_from.pk }}, + {% endif %} }; {% for item in build.incomplete_outputs %} @@ -412,13 +415,6 @@ $('#edit-notes').click(function() { }); }); -var buildInfo = { - pk: {{ build.pk }}, - quantity: {{ build.quantity }}, - completed: {{ build.completed }}, - part: {{ build.part.pk }}, -}; - {% if build.has_untracked_bom_items %} // Load allocation table for un-tracked parts loadBuildOutputAllocationTable(buildInfo, null); @@ -453,6 +449,9 @@ $("#btn-auto-allocate").on('click', function() { {{ build.part.pk }}, incomplete_bom_items, { + {% if build.take_from %} + source_location: {{ build.take_from.pk }}, + {% endif %} success: function(data) { $('#allocation-table-untracked').bootstrapTable('refresh'); } @@ -479,6 +478,9 @@ $('#allocate-selected-items').click(function() { {{ build.part.pk }}, bom_items, { + {% if build.take_from %} + source_location: {{ build.take_from.pk }}, + {% endif %} success: function(data) { $('#allocation-table-untracked').bootstrapTable('refresh'); } diff --git a/InvenTree/stock/api.py b/InvenTree/stock/api.py index e03d821bae..27c2426d53 100644 --- a/InvenTree/stock/api.py +++ b/InvenTree/stock/api.py @@ -821,7 +821,7 @@ class StockList(generics.ListCreateAPIView): if loc_id is not None: # Filter by 'null' location (i.e. top-level items) - if isNull(loc_id): + if isNull(loc_id) and not cascade: queryset = queryset.filter(location=None) else: try: diff --git a/InvenTree/templates/js/translated/build.js b/InvenTree/templates/js/translated/build.js index 325cb962a2..4e385d9f9a 100644 --- a/InvenTree/templates/js/translated/build.js +++ b/InvenTree/templates/js/translated/build.js @@ -172,6 +172,7 @@ function makeBuildOutputActionButtons(output, buildInfo, lines) { partId, bom_items, { + source_location: buildInfo.source_location, output: outputId, success: reloadTable, } @@ -407,6 +408,7 @@ function loadBuildOutputAllocationTable(buildInfo, output, options={}) { row, ], { + source_location: buildInfo.source_location, success: function(data) { $(table).bootstrapTable('refresh'); }, @@ -824,7 +826,8 @@ function loadBuildOutputAllocationTable(buildInfo, output, options={}) { * - bom_items: A list of BomItem objects to be allocated * * options: - * - outputId: ID / PK of the associated build output (or null for untracked items) + * - output: ID / PK of the associated build output (or null for untracked items) + * - source_location: ID / PK of the top-level StockLocation to take parts from (or null) */ function allocateStockToBuild(build_id, part_id, bom_items, options={}) { @@ -837,6 +840,8 @@ function allocateStockToBuild(build_id, part_id, bom_items, options={}) { sub_part_trackable: output_id != null }; + var source_location = options.source_location; + function renderBomItemRow(bom_item, quantity) { var pk = bom_item.pk; @@ -936,8 +941,22 @@ function allocateStockToBuild(build_id, part_id, bom_items, options={}) { return; } + var html = ``; + + // Render a "take from" input + html += constructField( + 'take_from', + { + type: 'related field', + label: '{% trans "Source Location" %}', + help_text: '{% trans "Select source location (leave blank to take from all locations)" %}', + required: false, + }, + {}, + ); + // Create table of parts - var html = ` + html += `