mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-10-31 21:25:42 +00:00 
			
		
		
		
	Add ability to include bom items inherited from parent parts in the API list
This commit is contained in:
		| @@ -822,7 +822,32 @@ class BomList(generics.ListCreateAPIView): | ||||
|         part = params.get('part', None) | ||||
|  | ||||
|         if part is not None: | ||||
|             queryset = queryset.filter(part=part) | ||||
|             """ | ||||
|             If we are filtering by "part", there are two cases to consider: | ||||
|  | ||||
|             a) Bom items which are defined for *this* part | ||||
|             b) Inherited parts which are defined for a *parent* part | ||||
|  | ||||
|             So we need to construct two queries! | ||||
|             """ | ||||
|  | ||||
|             # First, check that the part is actually valid! | ||||
|             try: | ||||
|                 part = Part.objects.get(pk=part) | ||||
|  | ||||
|                 # Construct a filter for matching the provided part | ||||
|                 local_part_filter = Q(part=part) | ||||
|              | ||||
|                 # Construct a filter for matching inherited items from parent parts | ||||
|                 parent_parts = part.get_ancestors(include_self=False) | ||||
|                 parent_ids = [p.pk for p in parent_parts] | ||||
|  | ||||
|                 parent_part_filter = Q(part__pk__in=parent_ids, inherited=True) | ||||
|  | ||||
|                 queryset = queryset.filter(local_part_filter | parent_part_filter) | ||||
|  | ||||
|             except (ValueError, Part.DoesNotExist): | ||||
|                 pass | ||||
|          | ||||
|         # Filter by sub-part? | ||||
|         sub_part = params.get('sub_part', None) | ||||
|   | ||||
| @@ -331,6 +331,7 @@ class EditBomItemForm(HelperForm): | ||||
|             'reference', | ||||
|             'overage', | ||||
|             'note', | ||||
|             'inherited', | ||||
|             'optional', | ||||
|         ] | ||||
|  | ||||
|   | ||||
| @@ -254,6 +254,18 @@ function loadBomTable(table, options) { | ||||
|     }); | ||||
|     */ | ||||
|  | ||||
|     cols.push({ | ||||
|         field: 'optional', | ||||
|         title: '{% trans "Optional" %}', | ||||
|         searchable: false, | ||||
|     }); | ||||
|  | ||||
|     cols.push({ | ||||
|         field: 'inherited', | ||||
|         title: '{% trans "Inherited" %}', | ||||
|         searchable: false, | ||||
|     }); | ||||
|  | ||||
|     cols.push( | ||||
|         { | ||||
|             'field': 'can_build', | ||||
|   | ||||
| @@ -44,6 +44,10 @@ function getAvailableTableFilters(tableKey) { | ||||
|                 type: 'bool', | ||||
|                 title: '{% trans "Validated" %}', | ||||
|             }, | ||||
|             inherited: { | ||||
|                 type: 'bool', | ||||
|                 title: '{% trans "Inherited" %}', | ||||
|             } | ||||
|         }; | ||||
|     } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user