mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-10-30 20:55:42 +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:
		| @@ -191,7 +191,19 @@ | ||||
|         </div> | ||||
|         {% 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 %} | ||||
|         <div class='alert alert-block alert-info'> | ||||
|             {% trans "This Build Order does not have any associated untracked BOM items" %} | ||||
| @@ -419,9 +431,12 @@ function reloadTable() { | ||||
| {% if build.active %} | ||||
| $("#btn-auto-allocate").on('click', function() { | ||||
|  | ||||
|     var bom_items = $("#allocation-table-untracked").bootstrapTable("getData"); | ||||
|  | ||||
|     allocateStockToBuild( | ||||
|         {{ build.pk }}, | ||||
|         {{ build.part.pk }}, | ||||
|         bom_items, | ||||
|         { | ||||
|             success: function(data) { | ||||
|                 $('#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() { | ||||
|     launchModalForm("/order/purchase-order/order-parts/", { | ||||
|         data: { | ||||
|   | ||||
| @@ -378,16 +378,24 @@ function loadBuildOutputAllocationTable(buildInfo, output, options={}) { | ||||
|             // Primary key of the 'sub_part' | ||||
|             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( | ||||
|                 buildId, | ||||
|                 partId, | ||||
|                 [ | ||||
|                     row, | ||||
|                 ], | ||||
|                 { | ||||
|                     success: function(data) { | ||||
|                         // TODO: Reload table | ||||
|                     }, | ||||
|                     parts: [ | ||||
|                         parseInt(pk), | ||||
|                     ] | ||||
|                 } | ||||
|             ); | ||||
|         }); | ||||
| @@ -798,19 +806,16 @@ function loadBuildOutputAllocationTable(buildInfo, output, options={}) { | ||||
|  * arguments: | ||||
|  * - buildId: ID / PK value for the build | ||||
|  * - partId: ID / PK value for the part being built | ||||
|  * - bom_items: A list of BomItem objects to be allocated | ||||
|  *  | ||||
|  * 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(build_id, part_id, options={}) { | ||||
| function allocateStockToBuild(build_id, part_id, bom_items, options={}) { | ||||
|  | ||||
|     // ID of the associated "build output" (or null) | ||||
|     var output_id = options.output || null; | ||||
|  | ||||
|     // Extract list of BOM items (or empty list) | ||||
|     var sub_part_ids = options.parts || []; | ||||
|  | ||||
|     var query_params = { | ||||
|         part: part_id, | ||||
|         sub_part_detail: true, | ||||
| @@ -884,33 +889,12 @@ function allocateStockToBuild(build_id, part_id, options={}) { | ||||
|         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 = ""; | ||||
|  | ||||
|                 for (var idx = 0; idx < response.length; idx++) { | ||||
|                     var item = response[idx]; | ||||
|     for (var idx = 0; idx < bom_items.length; idx++) { | ||||
|         var bom_item = bom_items[idx]; | ||||
|  | ||||
|                     var sub_part_id = item.sub_part; | ||||
|  | ||||
|                     // 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); | ||||
|         table_entries += renderBomItemRow(bom_item); | ||||
|     } | ||||
|  | ||||
|     if (bom_items.length == 0) { | ||||
| @@ -941,6 +925,7 @@ function allocateStockToBuild(build_id, part_id, options={}) { | ||||
|     </table> | ||||
|     `; | ||||
|                | ||||
|  | ||||
|     constructForm(`/api/build/${build_id}/allocate/`, { | ||||
|         method: 'POST', | ||||
|         fields: {}, | ||||
| @@ -1055,9 +1040,6 @@ function allocateStockToBuild(build_id, part_id, options={}) { | ||||
|         }, | ||||
|     }); | ||||
| } | ||||
|         } | ||||
|     ); | ||||
| } | ||||
|  | ||||
|  | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user