forked from erp-dev/erp
fix: printing api problem
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
Printing API 序列化器
|
||||
"""
|
||||
import json
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from rest_framework import serializers
|
||||
from rest_framework.fields import empty
|
||||
|
||||
@@ -149,8 +150,8 @@ class PlateImageInputSerializer(serializers.Serializer):
|
||||
|
||||
class PrintingOrderListSerializer(serializers.ModelSerializer):
|
||||
"""印染订单列表序列化器"""
|
||||
customer_name = serializers.CharField(source='customer.name', read_only=True)
|
||||
customer_phone = serializers.CharField(source='customer.mobile', read_only=True)
|
||||
customer_name = serializers.SerializerMethodField()
|
||||
customer_phone = serializers.SerializerMethodField()
|
||||
process_name = serializers.CharField(source='process.name', read_only=True)
|
||||
progress = serializers.IntegerField(read_only=True)
|
||||
jobs_status_summary = serializers.SerializerMethodField()
|
||||
@@ -177,6 +178,24 @@ class PrintingOrderListSerializer(serializers.ModelSerializer):
|
||||
]
|
||||
read_only_fields = ['id', 'human_id', 'created_at', 'updated_at', 'progress', 'print_count', 'merchant_id']
|
||||
|
||||
def get_customer_name(self, obj):
|
||||
if hasattr(obj, 'customer_name'):
|
||||
return obj.customer_name
|
||||
try:
|
||||
customer = getattr(obj, 'customer', None)
|
||||
except ObjectDoesNotExist:
|
||||
return None
|
||||
return getattr(customer, 'name', None)
|
||||
|
||||
def get_customer_phone(self, obj):
|
||||
if hasattr(obj, 'customer_phone'):
|
||||
return obj.customer_phone
|
||||
try:
|
||||
customer = getattr(obj, 'customer', None)
|
||||
except ObjectDoesNotExist:
|
||||
return None
|
||||
return getattr(customer, 'mobile', None)
|
||||
|
||||
def get_jobs_status_summary(self, obj):
|
||||
"""
|
||||
返回订单下所有 PrintingJob 按当前状态分组的数量汇总
|
||||
|
||||
Reference in New Issue
Block a user