forked from erp-dev/erp
feat: /api/v1/shipment/sales-items/by-printing-order/KD20135142/
This commit is contained in:
@@ -361,6 +361,7 @@ class SalesItemByPrintingOrderView(APIView):
|
||||
GET /api/v1/shipment/sales-items/by-printing-order/<printing_order_id>/
|
||||
|
||||
返回与该 PrintingOrder 下所有 PrintingJob 关联的 SalesItem 列表。
|
||||
路径参数既支持内部 ID,也支持 external_order_id。
|
||||
|
||||
查询参数:
|
||||
- include_already_has_shipment: 是否包含已关联出货单的销售品(true/false),默认 false
|
||||
@@ -393,12 +394,43 @@ class SalesItemByPrintingOrderView(APIView):
|
||||
permission_classes = [IsAuthenticated]
|
||||
|
||||
def get(self, request, printing_order_id):
|
||||
# 验证生产订单是否存在
|
||||
from printing.models import PrintingOrder
|
||||
|
||||
try:
|
||||
printing_order = PrintingOrder.objects.get(id=printing_order_id)
|
||||
except PrintingOrder.DoesNotExist:
|
||||
user = request.user
|
||||
if getattr(user, "is_superuser", False):
|
||||
base_queryset = PrintingOrder.objects.all()
|
||||
else:
|
||||
emp = getattr(user, "employee", None)
|
||||
merchant = getattr(emp, "merchant", None) if emp else None
|
||||
if not merchant:
|
||||
return Response(
|
||||
{"detail": f"生产订单 {printing_order_id} 不存在"},
|
||||
status=status.HTTP_404_NOT_FOUND,
|
||||
)
|
||||
base_queryset = PrintingOrder.objects.filter(merchant=merchant)
|
||||
|
||||
printing_order = None
|
||||
if printing_order_id.isdigit():
|
||||
printing_order = base_queryset.filter(id=int(printing_order_id)).first()
|
||||
|
||||
if printing_order is None:
|
||||
matched_orders = list(
|
||||
base_queryset.filter(external_order_id=printing_order_id).only("id")[:2]
|
||||
)
|
||||
if len(matched_orders) > 1:
|
||||
return Response(
|
||||
{
|
||||
"detail": (
|
||||
f"external_order_id {printing_order_id} 匹配到多个生产订单,"
|
||||
"请改用内部ID查询"
|
||||
)
|
||||
},
|
||||
status=status.HTTP_400_BAD_REQUEST,
|
||||
)
|
||||
if len(matched_orders) == 1:
|
||||
printing_order = matched_orders[0]
|
||||
|
||||
if printing_order is None:
|
||||
return Response(
|
||||
{"detail": f"生产订单 {printing_order_id} 不存在"},
|
||||
status=status.HTTP_404_NOT_FOUND,
|
||||
|
||||
Reference in New Issue
Block a user