forked from erp-dev/erp
feat: log formatted
This commit is contained in:
@@ -301,7 +301,7 @@ class PrintingOrderViewSet(CustomerVisibilityFilterMixin, LimitedModelViewSet):
|
||||
):
|
||||
queryset = queryset.filter(is_invalid=False)
|
||||
|
||||
if self.action in ["list", "retrieve"]:
|
||||
if self.action in ["list", "retrieve", "by_external_order_id"]:
|
||||
queryset = queryset.select_related("customer")
|
||||
# 预取 printing_jobs 及其 business_object,用于状态汇总统计
|
||||
# 同时预取 state_logs 和 process 相关数据以减少 job.status 属性调用时的 N+1 查询
|
||||
@@ -327,6 +327,29 @@ class PrintingOrderViewSet(CustomerVisibilityFilterMixin, LimitedModelViewSet):
|
||||
status=status.HTTP_405_METHOD_NOT_ALLOWED,
|
||||
)
|
||||
|
||||
@action(
|
||||
detail=False,
|
||||
methods=["get"],
|
||||
url_path=r"by-external-order-id/(?P<external_order_id>[^/.]+)",
|
||||
)
|
||||
def by_external_order_id(self, request, external_order_id=None):
|
||||
"""通过 external_order_id 获取印染订单详情"""
|
||||
normalized_external_order_id = str(external_order_id or "").strip()
|
||||
printing_order = (
|
||||
self.get_queryset()
|
||||
.filter(external_order_id=normalized_external_order_id)
|
||||
.order_by("id")
|
||||
.first()
|
||||
)
|
||||
if not printing_order:
|
||||
return Response(
|
||||
{"detail": "未找到该 external_order_id 对应的印染订单"},
|
||||
status=status.HTTP_404_NOT_FOUND,
|
||||
)
|
||||
|
||||
serializer = self.get_serializer(printing_order)
|
||||
return Response(serializer.data)
|
||||
|
||||
@action(detail=True, methods=["post"])
|
||||
def invalidate(self, request, pk=None):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user