diff --git a/InvenTree/templates/js/translated/build.js b/InvenTree/templates/js/translated/build.js
index c28a926e19..5715af9f3f 100644
--- a/InvenTree/templates/js/translated/build.js
+++ b/InvenTree/templates/js/translated/build.js
@@ -20,6 +20,7 @@
*/
/* exported
+ allocateStockToBuild,
editBuildOrder,
loadAllocationTable,
loadBuildOrderAllocationTable,
@@ -844,6 +845,52 @@ function allocateStockToBuild(buildId, partId, options={}) {
sub_part_trackable: outputId != null
};
+ function renderBomItemRow(bom_item, quantity) {
+
+ var pk = bom_item.pk;
+ var sub_part = bom_item.sub_part_detail;
+
+ var thumb = thumbnailImage(bom_item.sub_part_detail.thumbnail);
+
+ var delete_button = `
`;
+
+ delete_button += makeIconButton(
+ 'fa-times icon-red',
+ 'button-part-remove',
+ pk,
+ '{% trans "Remove row" %}',
+ );
+
+ delete_button += `
`;
+
+ var quantity_input = constructNumberInput(pk, {
+ value: quantity || 0,
+ min_value: 0,
+ title: '{% trans "Specify stock allocation quantity" %}',
+ });
+
+ var stock_input = constructRelatedFieldInput(`stock_query_${pk}`);
+
+ var html = `
+
+
+ ${thumb} ${sub_part.full_name}
+ |
+
+ ${stock_input}
+ |
+
+ ${quantity_input}
+ |
+
+ ${delete_button}
+ |
+
+ `;
+
+ return html;
+ }
+
inventreeGet(
'{% url "api-bom-list" %}',
bomItemQueryParams,
@@ -851,7 +898,9 @@ function allocateStockToBuild(buildId, partId, options={}) {
success: function(response) {
// List of BOM item objects we are interested in
- var bomItems = [];
+ var bom_items = [];
+
+ var table_entries = "";
for (var idx = 0; idx < response.length; idx++) {
var item = response[idx];
@@ -863,8 +912,78 @@ function allocateStockToBuild(buildId, partId, options={}) {
continue;
}
- bomItems.push(item);
+ // TODO: Ignore items which are already fully allocated
+
+ bom_items.push(item);
+
+ // Add HTML
+ table_entries += renderBomItemRow(item);
}
+
+ if (bom_items.length == 0) {
+
+ showAlertDialog(
+ '{% trans "Select Parts" %}',
+ '{% trans "You must select at least one part to allocate" %}',
+ );
+
+ return;
+ }
+
+ var modal = createNewModal({
+ title: '{% trans "Allocate Stock to Build" %}',
+ });
+
+ var html = `
+
+
+
+ {% trans "Part" %} |
+ {% trans "Stock Item" %} |
+ {% trans "Quantity" %} |
+ |
+
+
+
+ ${table_entries}
+
+
+ `;
+
+ constructFormBody({}, {
+ preFormContent: html,
+ fields: {},
+ confirm: true,
+ confirmMessage: '{% trans "Confirm Stock Allocation" %}',
+ modal: modal,
+ afterRender: function(fields, options) {
+
+ bom_items.forEach(function(bom_item) {
+ initializeRelatedField(
+ {
+ name: `stock_query_${bom_item.pk}`,
+ api_url: '{% url "api-stock-list" %}',
+ filters: {
+ part: bom_item.sub_part,
+ in_stock: true,
+ part_detail: true,
+ location_detail: true,
+ },
+ model: 'stockitem',
+ render_part_detail: false,
+ render_location_detail: true,
+ // TODO: Auto-assign value?
+ },
+ null,
+ options,
+ );
+ });
+
+ },
+ onSubmit: function(fields) {
+ // TODO
+ }
+ });
}
}
);