diff --git a/InvenTree/stock/api.py b/InvenTree/stock/api.py index 53d4b15d13..230f9bde4b 100644 --- a/InvenTree/stock/api.py +++ b/InvenTree/stock/api.py @@ -59,6 +59,18 @@ class StockDetail(generics.RetrieveUpdateDestroyAPIView): serializer_class = StockItemSerializer permission_classes = (permissions.IsAuthenticated,) + def get_serializer(self, *args, **kwargs): + + part_detail = str2bool(self.request.GET.get('part_detail', False)) + loc_detail = str2bool(self.request.GET.get('location_detail', False)) + + kwargs['part_detail'] = part_detail + kwargs['location_detail'] = loc_detail + + kwargs['context'] = self.get_serializer_context() + + return self.serializer_class(*args, **kwargs) + class StockFilter(FilterSet): """ FilterSet for advanced stock filtering. diff --git a/InvenTree/stock/serializers.py b/InvenTree/stock/serializers.py index f84667e352..d03b1f8770 100644 --- a/InvenTree/stock/serializers.py +++ b/InvenTree/stock/serializers.py @@ -59,6 +59,8 @@ class StockItemSerializer(InvenTreeModelSerializer): part_name = serializers.CharField(source='get_part_name', read_only=True) + part_image = serializers.CharField(source='part__image', read_only=True) + part_detail = PartBriefSerializer(source='part', many=False, read_only=True) location_detail = LocationBriefSerializer(source='location', many=False, read_only=True) @@ -81,8 +83,9 @@ class StockItemSerializer(InvenTreeModelSerializer): 'pk', 'url', 'part', - 'part_name', 'part_detail', + 'part_name', + 'part_image', 'supplier_part', 'location', 'location_detail',