1
0
forked from erp-dev/erp

fix: printing api problem

This commit is contained in:
2026-06-28 21:39:53 +08:00
parent cb6589c884
commit cc4607725c
4 changed files with 154 additions and 3 deletions

View File

@@ -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 按当前状态分组的数量汇总