InvenTree/InvenTree/stock/serializers.py

119 lines
2.7 KiB
Python
Raw Normal View History

2017-04-11 08:58:44 +00:00
from rest_framework import serializers
from .models import StockItem, StockLocation
from .models import StockItemTracking
2017-04-11 08:58:44 +00:00
from part.serializers import PartBriefSerializer
2019-04-13 23:23:24 +00:00
from InvenTree.serializers import UserSerializerBrief
class LocationBriefSerializer(serializers.ModelSerializer):
2019-04-13 23:23:24 +00:00
"""
Provides a brief serializer for a StockLocation object
"""
url = serializers.CharField(source='get_absolute_url', read_only=True)
class Meta:
model = StockLocation
fields = [
'pk',
'name',
'pathstring',
'url',
]
2017-04-11 08:58:44 +00:00
class StockTrackingSerializer(serializers.ModelSerializer):
url = serializers.CharField(source='get_absolute_url', read_only=True)
user = UserSerializerBrief(many=False, read_only=True)
class Meta:
model = StockItemTracking
fields = [
'pk',
'url',
'item',
'date',
'title',
'notes',
'quantity',
'user',
'system',
]
read_only_fields = [
'date',
'user',
'system',
'quantity',
]
2018-04-29 11:02:40 +00:00
class StockItemSerializer(serializers.ModelSerializer):
2017-04-11 08:58:44 +00:00
"""
2019-04-13 23:23:24 +00:00
Serializer for a StockItem
- Includes serialization for the linked part
- Includes serialization for the item location
"""
2019-04-13 23:39:01 +00:00
url = serializers.CharField(source='get_absolute_url', read_only=True)
part = PartBriefSerializer(many=False, read_only=True)
location = LocationBriefSerializer(many=False, read_only=True)
2017-04-11 08:58:44 +00:00
class Meta:
model = StockItem
2018-04-29 11:02:40 +00:00
fields = [
'pk',
2019-04-12 21:56:06 +00:00
'uuid',
2018-04-29 11:02:40 +00:00
'url',
'part',
'supplier_part',
'location',
2018-04-30 11:03:25 +00:00
'in_stock',
2018-04-29 11:02:40 +00:00
'quantity',
'serial',
'batch',
'status',
'notes',
]
2017-04-11 08:58:44 +00:00
""" These fields are read-only in this context.
They can be updated by accessing the appropriate API endpoints
"""
2018-04-29 11:02:40 +00:00
read_only_fields = [
'stocktake_date',
'stocktake_user',
'updated',
2019-04-13 23:23:24 +00:00
'quantity',
'in_stock'
2018-04-29 11:02:40 +00:00
]
class StockQuantitySerializer(serializers.ModelSerializer):
class Meta:
model = StockItem
fields = ('quantity',)
2017-04-11 08:58:44 +00:00
2018-05-03 15:33:21 +00:00
class LocationSerializer(serializers.ModelSerializer):
2017-04-11 08:58:44 +00:00
""" Detailed information about a stock location
"""
2018-05-03 15:33:21 +00:00
url = serializers.CharField(source='get_absolute_url', read_only=True)
2017-04-11 08:58:44 +00:00
class Meta:
model = StockLocation
2018-05-03 15:33:21 +00:00
fields = [
2019-04-13 23:23:24 +00:00
'pk',
'url',
'name',
'description',
'parent',
'pathstring'
]