forked from erp-dev/erp
60 lines
2.4 KiB
Python
60 lines
2.4 KiB
Python
"""
|
|
Printing 序列化器
|
|
"""
|
|
from rest_framework import serializers
|
|
from printing import models
|
|
|
|
|
|
class PrintingOrderListSerializer(serializers.ModelSerializer):
|
|
"""印染订单列表序列化器"""
|
|
customer_name = serializers.CharField(source='customer.name', read_only=True)
|
|
customer_phone = serializers.CharField(source='customer.phone', read_only=True)
|
|
|
|
class Meta:
|
|
model = models.PrintingOrder
|
|
fields = [
|
|
'id', 'human_id', 'customer', 'customer_name', 'customer_phone',
|
|
'fabric', 'width', 'is_urgent', 'area', 'address',
|
|
'is_fabric_received', 'outgoing_date', 'is_invalid',
|
|
'created_at', 'updated_at'
|
|
]
|
|
read_only_fields = ['id', 'human_id', 'created_at', 'updated_at']
|
|
|
|
|
|
class PrintingOrderDetailSerializer(serializers.ModelSerializer):
|
|
"""印染订单详情序列化器"""
|
|
customer_name = serializers.CharField(source='customer.name', read_only=True)
|
|
customer_phone = serializers.CharField(source='customer.phone', read_only=True)
|
|
customer_address = serializers.CharField(source='customer.address', read_only=True)
|
|
|
|
class Meta:
|
|
model = models.PrintingOrder
|
|
fields = [
|
|
'id', 'human_id', 'customer', 'customer_name', 'customer_phone', 'customer_address',
|
|
'fabric', 'width', 'is_urgent', 'area', 'address', 'fabric_source',
|
|
'is_fabric_received', 'craft', 'description', 'outgoing_date',
|
|
'curve', 'new_curve', 'position',
|
|
'printing_warn', 'rolling_warn', 'production_warn',
|
|
'is_invalid', 'created_at', 'updated_at'
|
|
]
|
|
read_only_fields = ['id', 'human_id', 'created_at', 'updated_at']
|
|
|
|
|
|
class PrintingOrderCreateUpdateSerializer(serializers.ModelSerializer):
|
|
"""印染订单创建/更新序列化器"""
|
|
|
|
class Meta:
|
|
model = models.PrintingOrder
|
|
fields = [
|
|
'customer', 'fabric', 'width', 'is_urgent', 'area', 'address',
|
|
'fabric_source', 'is_fabric_received', 'craft', 'description',
|
|
'outgoing_date', 'curve', 'new_curve', 'position',
|
|
'printing_warn', 'rolling_warn', 'production_warn', 'is_invalid'
|
|
]
|
|
|
|
def validate_customer(self, value):
|
|
"""验证客户是否存在"""
|
|
if not value:
|
|
raise serializers.ValidationError("客户不能为空")
|
|
return value
|