mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-11-04 07:05:41 +00:00 
			
		
		
		
	Extract a list of existing substitute parts from the form
This commit is contained in:
		@@ -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) {
 | 
					    function renderSubstituteRow(substitute) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        var pk = substitute.pk;
 | 
					        var pk = substitute.pk;
 | 
				
			||||||
@@ -171,7 +184,7 @@ function bomSubstitutesDialog(bom_item_id, substitutes, options={}) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        // Render a single row
 | 
					        // Render a single row
 | 
				
			||||||
        var html = `
 | 
					        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}'>
 | 
					            <td id='part-${pk}'>
 | 
				
			||||||
                <a href='/part/${part.pk}/'>
 | 
					                <a href='/part/${part.pk}/'>
 | 
				
			||||||
                    ${thumb} ${part.full_name}
 | 
					                    ${thumb} ${part.full_name}
 | 
				
			||||||
@@ -246,6 +259,16 @@ function bomSubstitutesDialog(bom_item_id, substitutes, options={}) {
 | 
				
			|||||||
            },
 | 
					            },
 | 
				
			||||||
            part: {
 | 
					            part: {
 | 
				
			||||||
                required: false,
 | 
					                required: false,
 | 
				
			||||||
 | 
					                adjustFilters: function(query, opts) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    var subs = getSubstituteIdValues(opts.modal);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    if (subs.length > 0) {
 | 
				
			||||||
 | 
					                        query.exclude_id = subs;
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    return query;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        preFormContent: html,
 | 
					        preFormContent: html,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1349,7 +1349,7 @@ function initializeRelatedField(field, fields, options) {
 | 
				
			|||||||
                
 | 
					                
 | 
				
			||||||
                // Allow custom run-time filter augmentation
 | 
					                // Allow custom run-time filter augmentation
 | 
				
			||||||
                if ('adjustFilters' in field) {
 | 
					                if ('adjustFilters' in field) {
 | 
				
			||||||
                    query = field.adjustFilters(query);
 | 
					                    query = field.adjustFilters(query, options);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                return query;
 | 
					                return query;
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user