2017-04-11 08:58:44 +00:00
|
|
|
from rest_framework import serializers
|
|
|
|
|
2017-04-21 13:47:04 +00:00
|
|
|
from .models import StockItem, StockLocation
|
2018-05-08 12:30:32 +00:00
|
|
|
from .models import StockItemTracking
|
2017-04-11 08:58:44 +00:00
|
|
|
|
2018-05-02 13:08:45 +00:00
|
|
|
from part.serializers import PartBriefSerializer
|
2019-04-13 23:23:24 +00:00
|
|
|
from InvenTree.serializers import UserSerializerBrief
|
|
|
|
|
2018-05-02 13:08:45 +00:00
|
|
|
|
|
|
|
class LocationBriefSerializer(serializers.ModelSerializer):
|
2019-04-13 23:23:24 +00:00
|
|
|
"""
|
|
|
|
Provides a brief serializer for a StockLocation object
|
|
|
|
"""
|
2018-05-02 13:08:45 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
2018-05-08 12:30:32 +00:00
|
|
|
class StockTrackingSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
url = serializers.CharField(source='get_absolute_url', read_only=True)
|
|
|
|
|
2018-05-10 11:20:12 +00:00
|
|
|
user = UserSerializerBrief(many=False, read_only=True)
|
|
|
|
|
2018-05-08 12:30:32 +00:00
|
|
|
class Meta:
|
|
|
|
model = StockItemTracking
|
|
|
|
fields = [
|
|
|
|
'pk',
|
|
|
|
'url',
|
|
|
|
'item',
|
|
|
|
'date',
|
|
|
|
'title',
|
|
|
|
'notes',
|
2019-04-12 14:14:10 +00:00
|
|
|
'quantity',
|
2018-05-08 12:30:32 +00:00
|
|
|
'user',
|
|
|
|
'system',
|
|
|
|
]
|
|
|
|
|
|
|
|
read_only_fields = [
|
|
|
|
'date',
|
|
|
|
'user',
|
|
|
|
'system',
|
2019-04-12 14:14:10 +00:00
|
|
|
'quantity',
|
2018-05-08 12:30:32 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2018-05-02 13:08:45 +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
|
|
|
|
2017-04-20 12:08:27 +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
|
|
|
]
|
2017-04-20 12:08:27 +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'
|
|
|
|
]
|