diff --git a/InvenTree/templates/js/translated/bom.js b/InvenTree/templates/js/translated/bom.js
index 7cab63153b..2cfae3a361 100644
--- a/InvenTree/templates/js/translated/bom.js
+++ b/InvenTree/templates/js/translated/bom.js
@@ -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 = `
-
+
${thumb} ${part.full_name}
@@ -246,6 +259,16 @@ function bomSubstitutesDialog(bom_item_id, substitutes, options={}) {
},
part: {
required: false,
+ adjustFilters: function(query, opts) {
+
+ var subs = getSubstituteIdValues(opts.modal);
+
+ if (subs.length > 0) {
+ query.exclude_id = subs;
+ }
+
+ return query;
+ }
},
},
preFormContent: html,
diff --git a/InvenTree/templates/js/translated/forms.js b/InvenTree/templates/js/translated/forms.js
index fecf5f1bd6..2483263219 100644
--- a/InvenTree/templates/js/translated/forms.js
+++ b/InvenTree/templates/js/translated/forms.js
@@ -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;
|