Merge pull request #2632 from SchrodingersGat/build-serial-number-guess

Build output allocation tweak
This commit is contained in:
Oliver 2022-02-16 08:37:47 +11:00 committed by GitHub
commit 6c32f5c60d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 2 deletions

View File

@ -1515,8 +1515,22 @@ function allocateStockToBuild(build_id, part_id, bom_items, options={}) {
// ID of the associated "build output" (or null)
var output_id = options.output || null;
var auto_fill_filters = {};
var source_location = options.source_location;
if (output_id) {
// Request information on the particular build output (stock item)
inventreeGet(`/api/stock/${output_id}/`, {}, {
success: function(output) {
if (output.quantity == 1 && output.serial != null) {
auto_fill_filters.serial = output.serial;
}
},
async: false,
});
}
function renderBomItemRow(bom_item, quantity) {
var pk = bom_item.pk;
@ -1703,7 +1717,9 @@ function allocateStockToBuild(build_id, part_id, bom_items, options={}) {
required: true,
render_part_detail: true,
render_location_detail: true,
render_stock_id: false,
auto_fill: true,
auto_fill_filters: auto_fill_filters,
onSelect: function(data, field, opts) {
// Adjust the 'quantity' field based on availability

View File

@ -1696,13 +1696,19 @@ function initializeRelatedField(field, fields, options={}) {
} else if (field.auto_fill) {
// Attempt to auto-fill the field
var filters = field.filters || {};
var filters = {};
// Update with nominal field fields
Object.assign(filters, field.filters || {});
// Update with filters only used for initial filtering
Object.assign(filters, field.auto_fill_filters || {});
// Enforce pagination, limit to a single return (for fast query)
filters.limit = 1;
filters.offset = 0;
inventreeGet(field.api_url, field.filters || {}, {
inventreeGet(field.api_url, filters || {}, {
success: function(data) {
// Only a single result is available, given the provided filters