forked from erp-dev/erp
fix: added merchant_id to printing_order and plate_order
This commit is contained in:
78
api_v1/views/shipment/views.py
Normal file
78
api_v1/views/shipment/views.py
Normal file
@@ -0,0 +1,78 @@
|
||||
"""
|
||||
Shipment API ViewSet
|
||||
"""
|
||||
from rest_framework import status
|
||||
from rest_framework.views import APIView
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
|
||||
from .serializers import SalesItemSerializer
|
||||
|
||||
|
||||
class SalesItemByPrintingOrderView(APIView):
|
||||
"""
|
||||
通过生产订单查询销售品
|
||||
|
||||
GET /api/v1/shipment/sales-items/by-printing-order/<printing_order_id>/
|
||||
|
||||
返回与该 PrintingOrder 下所有 PrintingJob 关联的 SalesItem 列表。
|
||||
|
||||
查询参数:
|
||||
- include_already_has_shipment: 是否包含已关联出货单的销售品(true/false),默认 false
|
||||
|
||||
返回:
|
||||
{
|
||||
"count": 5,
|
||||
"results": [
|
||||
{
|
||||
"id": 1,
|
||||
"name": "产品A",
|
||||
"quantity": "100.00",
|
||||
"unit": 1,
|
||||
"unit_display": "米",
|
||||
"position": "A1-01",
|
||||
"remark": "",
|
||||
"printing_job_id": 123,
|
||||
"customer_id": null,
|
||||
"shipment_id": null,
|
||||
"shipment_date": null,
|
||||
"created_at": "2026-01-14T10:00:00Z",
|
||||
"created_by_id": 1,
|
||||
"created_by_name": "张三"
|
||||
},
|
||||
...
|
||||
]
|
||||
}
|
||||
"""
|
||||
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:
|
||||
return Response(
|
||||
{'detail': f'生产订单 {printing_order_id} 不存在'},
|
||||
status=status.HTTP_404_NOT_FOUND
|
||||
)
|
||||
|
||||
# 获取查询参数
|
||||
include_already_has_shipment = request.query_params.get(
|
||||
'include_already_has_shipment', 'false'
|
||||
).lower() == 'true'
|
||||
|
||||
# 调用 shipment 业务逻辑
|
||||
from shipment.services import get_sales_items_by_printing_order
|
||||
sales_items = get_sales_items_by_printing_order(
|
||||
printing_order_id=printing_order.id,
|
||||
include_already_has_shipment=include_already_has_shipment,
|
||||
)
|
||||
|
||||
# 序列化返回
|
||||
serializer = SalesItemSerializer(sales_items, many=True)
|
||||
|
||||
return Response({
|
||||
'count': len(serializer.data),
|
||||
'results': serializer.data
|
||||
})
|
||||
Reference in New Issue
Block a user