forked from erp-dev/erp
feat: red flush and cost
This commit is contained in:
@@ -10,7 +10,7 @@ from rest_framework.permissions import BasePermission
|
||||
from rest_framework.permissions import DjangoModelPermissions
|
||||
from rest_framework.parsers import MultiPartParser, FormParser, JSONParser
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.db.models import CharField, Exists, OuterRef, Prefetch
|
||||
from django.db.models import CharField, Exists, OuterRef, Prefetch, Subquery
|
||||
from django.db.models.functions import Cast, Coalesce
|
||||
from django.views.decorators.cache import cache_page
|
||||
from django.views.decorators.http import condition
|
||||
@@ -1065,13 +1065,14 @@ class PlateOrderViewSet(CustomerVisibilityFilterMixin, LimitedModelViewSet):
|
||||
def get_serializer_class(self):
|
||||
"""根据动作选择序列化器"""
|
||||
from .serializers import (
|
||||
PlateOrderKanbanListSerializer,
|
||||
PlateOrderListSerializer,
|
||||
PlateOrderDetailSerializer,
|
||||
PlateOrderCreateUpdateSerializer,
|
||||
)
|
||||
|
||||
if self.action == "list":
|
||||
return PlateOrderListSerializer
|
||||
return PlateOrderKanbanListSerializer
|
||||
elif self.action in ["create", "update", "partial_update"]:
|
||||
return PlateOrderCreateUpdateSerializer
|
||||
else: # retrieve
|
||||
@@ -1092,13 +1093,24 @@ class PlateOrderViewSet(CustomerVisibilityFilterMixin, LimitedModelViewSet):
|
||||
|
||||
if self.action in ["list", "retrieve"]:
|
||||
queryset = queryset.select_related(
|
||||
"customer", "salesperson", "merchandiser", "business_object"
|
||||
"customer",
|
||||
"salesperson",
|
||||
"merchandiser",
|
||||
"business_object",
|
||||
"created_by__employee",
|
||||
)
|
||||
# 为搜索提供 design_code 的兜底(为空时使用主键字符串)
|
||||
|
||||
# 预取流程名称(process 是 IntegerField 非外键,用 Subquery 避免 N+1)
|
||||
from stateflow.models import Process
|
||||
|
||||
queryset = queryset.annotate(
|
||||
design_code_normalized=Coalesce(
|
||||
"design_code", Cast("id", output_field=CharField())
|
||||
)
|
||||
),
|
||||
annotated_process_name=Subquery(
|
||||
Process.objects.filter(id=OuterRef("process")).values("name")[:1],
|
||||
output_field=CharField(),
|
||||
),
|
||||
)
|
||||
return queryset
|
||||
|
||||
|
||||
Reference in New Issue
Block a user