forked from erp-dev/erp
125 lines
4.7 KiB
Python
125 lines
4.7 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
|
|
|
|
|
|
class PrintingJobListSerializer(serializers.ModelSerializer):
|
|
"""印染款式明细列表序列化器"""
|
|
printing_order_id = serializers.CharField(source='printing_order.human_id', read_only=True)
|
|
product_name = serializers.CharField(source='product.name', read_only=True)
|
|
|
|
class Meta:
|
|
model = models.PrintingJob
|
|
fields = [
|
|
'id', 'printing_order', 'printing_order_id', 'product', 'product_name',
|
|
'quantity', 'unit', 'size', 'pieces', 'description',
|
|
'created_at', 'updated_at'
|
|
]
|
|
read_only_fields = ['id', 'created_at', 'updated_at']
|
|
|
|
|
|
class PrintingJobDetailSerializer(serializers.ModelSerializer):
|
|
"""印染款式明细详情序列化器"""
|
|
printing_order_id = serializers.CharField(source='printing_order.human_id', read_only=True)
|
|
product_name = serializers.CharField(source='product.name', read_only=True)
|
|
product_code = serializers.CharField(source='product.human_id', read_only=True)
|
|
|
|
class Meta:
|
|
model = models.PrintingJob
|
|
fields = [
|
|
'id', 'printing_order', 'printing_order_id', 'product', 'product_name', 'product_code',
|
|
'quantity', 'unit', 'size', 'pieces', 'description',
|
|
'created_at', 'updated_at'
|
|
]
|
|
read_only_fields = ['id', 'created_at', 'updated_at']
|
|
|
|
|
|
class PrintingJobCreateUpdateSerializer(serializers.ModelSerializer):
|
|
"""印染款式明细创建/更新序列化器"""
|
|
|
|
class Meta:
|
|
model = models.PrintingJob
|
|
fields = [
|
|
'printing_order', 'product', 'quantity', 'unit', 'size', 'pieces', 'description'
|
|
]
|
|
|
|
def validate_printing_order(self, value):
|
|
"""验证印染订单是否存在"""
|
|
if not value:
|
|
raise serializers.ValidationError("印染订单不能为空")
|
|
return value
|
|
|
|
def validate_product(self, value):
|
|
"""验证产品是否存在"""
|
|
if not value:
|
|
raise serializers.ValidationError("产品不能为空")
|
|
return value
|
|
|
|
def validate_quantity(self, value):
|
|
"""验证数量"""
|
|
if value <= 0:
|
|
raise serializers.ValidationError("数量必须大于0")
|
|
return value
|
|
|
|
def validate_pieces(self, value):
|
|
"""验证件数"""
|
|
if value <= 0:
|
|
raise serializers.ValidationError("件数必须大于0")
|
|
return value
|