mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
4218cf8b45
- Cusomizations made to bootstrap-table-group-by.js - Group by part name - Display total stock count per group - Only group if there are more than 1 item in the group - Groups send checkbox signals through appropriately!
164 lines
4.0 KiB
Python
164 lines
4.0 KiB
Python
"""
|
|
JSON serializers for Stock app
|
|
"""
|
|
|
|
from rest_framework import serializers
|
|
|
|
from .models import StockItem, StockLocation
|
|
from .models import StockItemTracking
|
|
|
|
from part.serializers import PartBriefSerializer
|
|
from InvenTree.serializers import UserSerializerBrief
|
|
|
|
|
|
class LocationBriefSerializer(serializers.ModelSerializer):
|
|
"""
|
|
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',
|
|
]
|
|
|
|
|
|
class StockItemSerializerBrief(serializers.ModelSerializer):
|
|
""" Brief serializers for a StockItem """
|
|
|
|
location_name = serializers.CharField(source='location', read_only=True)
|
|
part_name = serializers.CharField(source='part.full_name', read_only=True)
|
|
|
|
class Meta:
|
|
model = StockItem
|
|
fields = [
|
|
'pk',
|
|
'part',
|
|
'part_name',
|
|
'supplier_part',
|
|
'location',
|
|
'location_name',
|
|
'quantity',
|
|
]
|
|
|
|
|
|
class StockItemSerializer(serializers.ModelSerializer):
|
|
""" Serializer for a StockItem:
|
|
|
|
- Includes serialization for the linked part
|
|
- Includes serialization for the item location
|
|
"""
|
|
|
|
url = serializers.CharField(source='get_absolute_url', read_only=True)
|
|
status_text = serializers.CharField(source='get_status_display', read_only=True)
|
|
|
|
part_name = serializers.CharField(source='get_part_name', read_only=True)
|
|
|
|
part_detail = PartBriefSerializer(source='part', many=False, read_only=True)
|
|
location_detail = LocationBriefSerializer(source='location', many=False, read_only=True)
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
part_detail = kwargs.pop('part_detail', False)
|
|
location_detail = kwargs.pop('location_detail', False)
|
|
|
|
super(StockItemSerializer, self).__init__(*args, **kwargs)
|
|
|
|
if part_detail is not True:
|
|
self.fields.pop('part_detail')
|
|
|
|
if location_detail is not True:
|
|
self.fields.pop('location_detail')
|
|
|
|
class Meta:
|
|
model = StockItem
|
|
fields = [
|
|
'pk',
|
|
'url',
|
|
'part',
|
|
'part_name',
|
|
'part_detail',
|
|
'supplier_part',
|
|
'location',
|
|
'location_detail',
|
|
'in_stock',
|
|
'quantity',
|
|
'serial',
|
|
'batch',
|
|
'status',
|
|
'status_text',
|
|
'notes',
|
|
]
|
|
|
|
""" These fields are read-only in this context.
|
|
They can be updated by accessing the appropriate API endpoints
|
|
"""
|
|
read_only_fields = [
|
|
'stocktake_date',
|
|
'stocktake_user',
|
|
'updated',
|
|
'quantity',
|
|
'in_stock'
|
|
]
|
|
|
|
|
|
class StockQuantitySerializer(serializers.ModelSerializer):
|
|
|
|
class Meta:
|
|
model = StockItem
|
|
fields = ('quantity',)
|
|
|
|
|
|
class LocationSerializer(serializers.ModelSerializer):
|
|
""" Detailed information about a stock location
|
|
"""
|
|
|
|
url = serializers.CharField(source='get_absolute_url', read_only=True)
|
|
|
|
class Meta:
|
|
model = StockLocation
|
|
fields = [
|
|
'pk',
|
|
'url',
|
|
'name',
|
|
'description',
|
|
'parent',
|
|
'pathstring'
|
|
]
|
|
|
|
|
|
class StockTrackingSerializer(serializers.ModelSerializer):
|
|
""" Serializer for StockItemTracking model """
|
|
|
|
url = serializers.CharField(source='get_absolute_url', read_only=True)
|
|
|
|
user = UserSerializerBrief(many=False, read_only=True)
|
|
|
|
item = StockItemSerializerBrief(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',
|
|
]
|