mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-28 19:46:46 +00:00
Refactor allocation form
- The data is already loaded in the main table! - Why would we want to throw that data away?
This commit is contained in:
parent
28509dbd68
commit
17df4ca91e
@ -191,7 +191,19 @@
|
|||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<table class='table table-striped table-condensed' id='allocation-table-untracked'></table>
|
<div id='unallocated-toolbar'>
|
||||||
|
<div class='button-toolbar container-fluid' style='float: right;'>
|
||||||
|
<div class='btn-group'>
|
||||||
|
<button id='allocate-selected-items' class='btn btn-success' title='{% trans "Allocate selected items" %}'>
|
||||||
|
<span class='fas fa-sign-in-alt'></span>
|
||||||
|
</button>
|
||||||
|
<div class='filter-list' id='filter-list-build-items'>
|
||||||
|
<!-- Empty div for table filters-->
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<table class='table table-striped table-condensed' id='allocation-table-untracked' data-toolbar='#unallocated-toolbar'></table>
|
||||||
{% else %}
|
{% else %}
|
||||||
<div class='alert alert-block alert-info'>
|
<div class='alert alert-block alert-info'>
|
||||||
{% trans "This Build Order does not have any associated untracked BOM items" %}
|
{% trans "This Build Order does not have any associated untracked BOM items" %}
|
||||||
@ -419,9 +431,12 @@ function reloadTable() {
|
|||||||
{% if build.active %}
|
{% if build.active %}
|
||||||
$("#btn-auto-allocate").on('click', function() {
|
$("#btn-auto-allocate").on('click', function() {
|
||||||
|
|
||||||
|
var bom_items = $("#allocation-table-untracked").bootstrapTable("getData");
|
||||||
|
|
||||||
allocateStockToBuild(
|
allocateStockToBuild(
|
||||||
{{ build.pk }},
|
{{ build.pk }},
|
||||||
{{ build.part.pk }},
|
{{ build.part.pk }},
|
||||||
|
bom_items,
|
||||||
{
|
{
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
$('#allocation-table-untracked').bootstrapTable('refresh');
|
$('#allocation-table-untracked').bootstrapTable('refresh');
|
||||||
@ -439,6 +454,22 @@ $('#btn-unallocate').on('click', function() {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('#allocate-selected-items').click(function() {
|
||||||
|
|
||||||
|
var bom_items = $("#allocation-table-untracked").bootstrapTable("getSelections");
|
||||||
|
|
||||||
|
allocateStockToBuild(
|
||||||
|
{{ build.pk }},
|
||||||
|
{{ build.part.pk }},
|
||||||
|
bom_items,
|
||||||
|
{
|
||||||
|
success: function(data) {
|
||||||
|
$('#allocation-table-untracked').bootstrapTable('refresh');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
$("#btn-order-parts").click(function() {
|
$("#btn-order-parts").click(function() {
|
||||||
launchModalForm("/order/purchase-order/order-parts/", {
|
launchModalForm("/order/purchase-order/order-parts/", {
|
||||||
data: {
|
data: {
|
||||||
|
@ -378,16 +378,24 @@ function loadBuildOutputAllocationTable(buildInfo, output, options={}) {
|
|||||||
// Primary key of the 'sub_part'
|
// Primary key of the 'sub_part'
|
||||||
var pk = $(this).attr('pk');
|
var pk = $(this).attr('pk');
|
||||||
|
|
||||||
|
// Extract BomItem information from this row
|
||||||
|
var row = $(table).bootstrapTable('getRowByUniqueId', pk);
|
||||||
|
|
||||||
|
if (!row) {
|
||||||
|
console.log("WARNING: getRowByUniqueId returned null");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
allocateStockToBuild(
|
allocateStockToBuild(
|
||||||
buildId,
|
buildId,
|
||||||
partId,
|
partId,
|
||||||
|
[
|
||||||
|
row,
|
||||||
|
],
|
||||||
{
|
{
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
// TODO: Reload table
|
// TODO: Reload table
|
||||||
},
|
},
|
||||||
parts: [
|
|
||||||
parseInt(pk),
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -798,19 +806,16 @@ function loadBuildOutputAllocationTable(buildInfo, output, options={}) {
|
|||||||
* arguments:
|
* arguments:
|
||||||
* - buildId: ID / PK value for the build
|
* - buildId: ID / PK value for the build
|
||||||
* - partId: ID / PK value for the part being built
|
* - partId: ID / PK value for the part being built
|
||||||
|
* - bom_items: A list of BomItem objects to be allocated
|
||||||
*
|
*
|
||||||
* options:
|
* options:
|
||||||
* - outputId: ID / PK of the associated build output (or null for untracked items)
|
* - 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(build_id, part_id, options={}) {
|
function allocateStockToBuild(build_id, part_id, bom_items, options={}) {
|
||||||
|
|
||||||
// ID of the associated "build output" (or null)
|
// ID of the associated "build output" (or null)
|
||||||
var output_id = options.output || null;
|
var output_id = options.output || null;
|
||||||
|
|
||||||
// Extract list of BOM items (or empty list)
|
|
||||||
var sub_part_ids = options.parts || [];
|
|
||||||
|
|
||||||
var query_params = {
|
var query_params = {
|
||||||
part: part_id,
|
part: part_id,
|
||||||
sub_part_detail: true,
|
sub_part_detail: true,
|
||||||
@ -884,33 +889,12 @@ function allocateStockToBuild(build_id, part_id, options={}) {
|
|||||||
return html;
|
return html;
|
||||||
}
|
}
|
||||||
|
|
||||||
inventreeGet(
|
|
||||||
'{% url "api-bom-list" %}',
|
|
||||||
query_params,
|
|
||||||
{
|
|
||||||
success: function(response) {
|
|
||||||
|
|
||||||
// List of BOM item objects we are interested in
|
|
||||||
var bom_items = [];
|
|
||||||
|
|
||||||
var table_entries = "";
|
var table_entries = "";
|
||||||
|
|
||||||
for (var idx = 0; idx < response.length; idx++) {
|
for (var idx = 0; idx < bom_items.length; idx++) {
|
||||||
var item = response[idx];
|
var bom_item = bom_items[idx];
|
||||||
|
|
||||||
var sub_part_id = item.sub_part;
|
table_entries += renderBomItemRow(bom_item);
|
||||||
|
|
||||||
// Check if we are interested in this item
|
|
||||||
if (sub_part_ids.length > 0 && !sub_part_ids.includes(sub_part_id)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Ignore items which are already fully allocated
|
|
||||||
|
|
||||||
bom_items.push(item);
|
|
||||||
|
|
||||||
// Add HTML
|
|
||||||
table_entries += renderBomItemRow(item);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bom_items.length == 0) {
|
if (bom_items.length == 0) {
|
||||||
@ -941,6 +925,7 @@ function allocateStockToBuild(build_id, part_id, options={}) {
|
|||||||
</table>
|
</table>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
|
||||||
constructForm(`/api/build/${build_id}/allocate/`, {
|
constructForm(`/api/build/${build_id}/allocate/`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
fields: {},
|
fields: {},
|
||||||
@ -1054,9 +1039,6 @@ function allocateStockToBuild(build_id, part_id, options={}) {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user