diff --git a/InvenTree/part/api.py b/InvenTree/part/api.py index 9db4ef5425..f866a08850 100644 --- a/InvenTree/part/api.py +++ b/InvenTree/part/api.py @@ -603,7 +603,20 @@ class BomList(generics.ListCreateAPIView): """ serializer_class = part_serializers.BomItemSerializer - + + def list(self, request, *args, **kwargs): + + queryset = self.filter_queryset(self.get_queryset()) + + serializer = self.get_serializer(queryset, many=True) + + data = serializer.data + + if request.is_ajax(): + return JsonResponse(data, safe=False) + else: + return Response(data) + def get_serializer(self, *args, **kwargs): # Do we wish to include extra detail? @@ -622,8 +635,10 @@ class BomList(generics.ListCreateAPIView): return self.serializer_class(*args, **kwargs) - def get_queryset(self): + def get_queryset(self, *args, **kwargs): + queryset = BomItem.objects.all() + queryset = self.get_serializer_class().setup_eager_loading(queryset) return queryset diff --git a/InvenTree/part/serializers.py b/InvenTree/part/serializers.py index d9c041c252..c1ecfb5cce 100644 --- a/InvenTree/part/serializers.py +++ b/InvenTree/part/serializers.py @@ -305,8 +305,13 @@ class BomItemSerializer(InvenTreeModelSerializer): price_range = serializers.CharField(read_only=True) quantity = serializers.FloatField() + + part = serializers.PrimaryKeyRelatedField(queryset=Part.objects.filter(assembly=True)) part_detail = PartBriefSerializer(source='part', many=False, read_only=True) + + sub_part = serializers.PrimaryKeyRelatedField(queryset=Part.objects.filter(component=True)) + sub_part_detail = PartBriefSerializer(source='sub_part', many=False, read_only=True) validated = serializers.BooleanField(read_only=True, source='is_line_valid') @@ -331,6 +336,7 @@ class BomItemSerializer(InvenTreeModelSerializer): queryset = queryset.prefetch_related('part') queryset = queryset.prefetch_related('part__category') queryset = queryset.prefetch_related('part__stock_items') + queryset = queryset.prefetch_related('sub_part') queryset = queryset.prefetch_related('sub_part__category') queryset = queryset.prefetch_related('sub_part__stock_items')