forked from erp-dev/erp
fix: added merchant_id in models of shipment module
This commit is contained in:
@@ -6,7 +6,12 @@ from rest_framework.views import APIView
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
|
||||
from .serializers import SalesItemSerializer, ShipmentSerializer, ShipmentCreateSerializer
|
||||
from .serializers import (
|
||||
SalesItemSerializer,
|
||||
ShipmentSerializer,
|
||||
ShipmentCreateNormalSerializer,
|
||||
ShipmentCreateExternalSerializer,
|
||||
)
|
||||
|
||||
|
||||
class ShipmentCreateView(APIView):
|
||||
@@ -41,7 +46,7 @@ class ShipmentCreateView(APIView):
|
||||
|
||||
def post(self, request):
|
||||
# 验证请求数据
|
||||
serializer = ShipmentCreateSerializer(data=request.data)
|
||||
serializer = ShipmentCreateNormalSerializer(data=request.data)
|
||||
if not serializer.is_valid():
|
||||
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
@@ -65,6 +70,43 @@ class ShipmentCreateView(APIView):
|
||||
return Response(response_serializer.data, status=status.HTTP_201_CREATED)
|
||||
|
||||
|
||||
class ShipmentExternalCreateView(APIView):
|
||||
"""
|
||||
创建出货单(external 版)
|
||||
|
||||
POST /api/v1/shipment/shipments/external/
|
||||
|
||||
特点:
|
||||
- external_id 必填
|
||||
- external_finished_products 必填(数组)
|
||||
- 不绑定任何销售品
|
||||
"""
|
||||
permission_classes = [IsAuthenticated]
|
||||
|
||||
def post(self, request):
|
||||
serializer = ShipmentCreateExternalSerializer(data=request.data)
|
||||
if not serializer.is_valid():
|
||||
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
data = serializer.validated_data
|
||||
|
||||
from shipment.services import create_external_shipment
|
||||
try:
|
||||
shipment = create_external_shipment(
|
||||
customer_id=data['customer'],
|
||||
shipment_date=data['shipment_date'],
|
||||
external_id=data['external_id'],
|
||||
external_finished_products=data['external_finished_products'],
|
||||
created_by=request.user,
|
||||
remark=data.get('remark', ''),
|
||||
)
|
||||
except ValueError as e:
|
||||
return Response({'detail': str(e)}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
response_serializer = ShipmentSerializer(shipment)
|
||||
return Response(response_serializer.data, status=status.HTTP_201_CREATED)
|
||||
|
||||
|
||||
class SalesItemByPrintingOrderView(APIView):
|
||||
"""
|
||||
通过生产订单查询销售品
|
||||
|
||||
Reference in New Issue
Block a user