2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-01 11:10:54 +00:00

Merge branch 'master' into build-output-complete

This commit is contained in:
Oliver
2021-10-16 13:18:35 +11:00
25 changed files with 562 additions and 107 deletions

View File

@ -157,6 +157,19 @@ function bomSubstitutesDialog(bom_item_id, substitutes, options={}) {
}
}
// Extract a list of all existing "substitute" id values
function getSubstituteIdValues(modal) {
var id_values = [];
$(modal).find('.substitute-row').each(function(el) {
var part = $(this).attr('part');
id_values.push(part);
});
return id_values;
}
function renderSubstituteRow(substitute) {
var pk = substitute.pk;
@ -171,7 +184,7 @@ function bomSubstitutesDialog(bom_item_id, substitutes, options={}) {
// Render a single row
var html = `
<tr id='substitute-row-${pk}' class='substitute-row'>
<tr id='substitute-row-${pk}' class='substitute-row' part='${substitute.part}'>
<td id='part-${pk}'>
<a href='/part/${part.pk}/'>
${thumb} ${part.full_name}
@ -246,6 +259,21 @@ function bomSubstitutesDialog(bom_item_id, substitutes, options={}) {
},
part: {
required: false,
adjustFilters: function(query, opts) {
var subs = getSubstituteIdValues(opts.modal);
// Also exclude the "master" part (if provided)
if (options.sub_part) {
subs.push(options.sub_part);
}
if (subs.length > 0) {
query.exclude_id = subs;
}
return query;
}
},
},
preFormContent: html,
@ -801,6 +829,7 @@ function loadBomTable(table, options) {
subs,
{
table: table,
sub_part: row.sub_part,
}
);
});

View File

@ -1349,7 +1349,7 @@ function initializeRelatedField(field, fields, options) {
// Allow custom run-time filter augmentation
if ('adjustFilters' in field) {
query = field.adjustFilters(query);
query = field.adjustFilters(query, options);
}
return query;