mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Improve API filtering for StockItem
This commit is contained in:
parent
197a3e6731
commit
e02b692ab2
@ -538,11 +538,10 @@ class StockList(generics.ListCreateAPIView):
|
|||||||
try:
|
try:
|
||||||
part = Part.objects.get(pk=part_id)
|
part = Part.objects.get(pk=part_id)
|
||||||
|
|
||||||
# If the part is a Template part, select stock items for any "variant" parts under that template
|
# Filter by any parts "under" the given part
|
||||||
if part.is_template:
|
parts = part.get_descendants(include_self=True)
|
||||||
queryset = queryset.filter(part__in=[part.id for part in Part.objects.filter(variant_of=part_id)])
|
|
||||||
else:
|
queryset = queryset.filter(part__in=parts)
|
||||||
queryset = queryset.filter(part=part_id)
|
|
||||||
|
|
||||||
except (ValueError, Part.DoesNotExist):
|
except (ValueError, Part.DoesNotExist):
|
||||||
raise ValidationError({"part": "Invalid Part ID specified"})
|
raise ValidationError({"part": "Invalid Part ID specified"})
|
||||||
|
Loading…
Reference in New Issue
Block a user