mirror of
https://github.com/inventree/InvenTree.git
synced 2025-07-13 08:21:26 +00:00
Updates for stock serializer
This commit is contained in:
@ -56,18 +56,28 @@ class StockItemSerializer(InvenTreeModelSerializer):
|
||||
- Includes serialization for the item location
|
||||
"""
|
||||
|
||||
url = serializers.CharField(source='get_absolute_url', read_only=True)
|
||||
@staticmethod
|
||||
def prefetch_queryset(queryset):
|
||||
"""
|
||||
Prefetch related database tables,
|
||||
to reduce database hits.
|
||||
"""
|
||||
|
||||
return queryset.prefetch_related(
|
||||
'supplier_part',
|
||||
'supplier_part__supplier',
|
||||
'supplier_part__manufacturer',
|
||||
'location',
|
||||
'part'
|
||||
)
|
||||
|
||||
status_text = serializers.CharField(source='get_status_display', read_only=True)
|
||||
|
||||
part_name = serializers.CharField(source='get_part_name', read_only=True)
|
||||
|
||||
part_image = serializers.CharField(source='part__image', read_only=True)
|
||||
|
||||
tracking_items = serializers.IntegerField(source='tracking_info_count', read_only=True)
|
||||
#tracking_items = serializers.IntegerField(source='tracking_info_count', read_only=True)
|
||||
|
||||
part_detail = PartBriefSerializer(source='part', many=False, read_only=True)
|
||||
location_detail = LocationBriefSerializer(source='location', many=False, read_only=True)
|
||||
supplier_detail = SupplierPartSerializer(source='supplier_part', many=False, read_only=True)
|
||||
supplier_part_detail = SupplierPartSerializer(source='supplier_part', many=False, read_only=True)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
||||
@ -84,7 +94,7 @@ class StockItemSerializer(InvenTreeModelSerializer):
|
||||
self.fields.pop('location_detail')
|
||||
|
||||
if supplier_detail is not True:
|
||||
self.fields.pop('supplier_detail')
|
||||
self.fields.pop('supplier_part_detail')
|
||||
|
||||
class Meta:
|
||||
model = StockItem
|
||||
@ -97,18 +107,16 @@ class StockItemSerializer(InvenTreeModelSerializer):
|
||||
'notes',
|
||||
'part',
|
||||
'part_detail',
|
||||
'part_name',
|
||||
'part_image',
|
||||
'pk',
|
||||
'quantity',
|
||||
'serial',
|
||||
'supplier_part',
|
||||
'supplier_detail',
|
||||
'supplier_part_detail',
|
||||
'status',
|
||||
'status_text',
|
||||
'tracking_items',
|
||||
#'tracking_items',
|
||||
'uid',
|
||||
'url',
|
||||
#'url',
|
||||
]
|
||||
|
||||
""" These fields are read-only in this context.
|
||||
|
Reference in New Issue
Block a user