Add part_detail and location_detail to the StockItem detail class

This commit is contained in:
Oliver Walters 2020-04-06 08:38:10 +10:00
parent fce26c80b7
commit 2530313e68
2 changed files with 16 additions and 1 deletions

View File

@ -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.

View File

@ -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',