1
0
forked from erp-dev/erp

feat: external_order refetch api

This commit is contained in:
2026-04-16 17:34:16 +08:00
parent 4f3109546d
commit e109c00837
9 changed files with 1547 additions and 0 deletions

View File

@@ -10,6 +10,7 @@ from .printing import (
PrintingJobBatchAdvancePreviewView,
PrintingJobBatchAdvanceSubmitView,
PrintingJobBatchAddParametersView,
PrintingOrderExternalSnapshotSyncView,
PlateOrderByProcessNodeView,
PlateOrderByProcessView,
PlateOrderByStateStatusView,
@@ -40,6 +41,7 @@ __all__ = [
'PrintingJobBatchAdvancePreviewView',
'PrintingJobBatchAdvanceSubmitView',
'PrintingJobBatchAddParametersView',
'PrintingOrderExternalSnapshotSyncView',
'PlateOrderByProcessNodeView',
'PlateOrderByProcessView',
'PlateOrderByStateStatusView',

View File

@@ -13,6 +13,10 @@ from rest_framework.views import APIView
from basic_info import models as basic_models
from printing import models as printing_models
from api_v1.tasks import (
ExternalPrintingOrderSnapshotSyncError,
sync_external_printing_order_snapshot_impl,
)
from api_man.serializers import ProductSerializer
from api_v1.views.printing.serializers import (
PlateOrderListSerializer as PlateOrderListV1Serializer,
@@ -1529,6 +1533,63 @@ class PrintingOrderBatchAdvanceRecordsView(APIView):
})
class PrintingOrderExternalSnapshotSyncRequestSerializer(serializers.Serializer):
external_order_id = serializers.CharField(max_length=100, help_text='外部订单编号')
allow_reset_stateflow = serializers.BooleanField(
required=False,
default=False,
help_text='是否允许先撤销目标订单下已有的所有工序,再执行覆盖同步',
)
def validate_external_order_id(self, value):
normalized = str(value or '').strip()
if not normalized:
raise serializers.ValidationError('external_order_id 不能为空')
return normalized
class PrintingOrderExternalSnapshotSyncView(APIView):
"""
按 external_order_id 触发外部订单快照同步。
行为:
- 若目标订单任意 printing_job 已关联销售品,则立即失败并记录审计
- 若目标订单存在已执行工序,默认失败;可通过 allow_reset_stateflow=true 先撤销全部工序后再覆盖
- 成功时复用现有外部订单映射逻辑覆盖 PrintingOrder / PrintingJob
"""
permission_classes = [permissions.IsAuthenticated, IsPrintingFactory]
def post(self, request):
srz = PrintingOrderExternalSnapshotSyncRequestSerializer(data=request.data)
srz.is_valid(raise_exception=True)
payload = srz.validated_data
try:
result = sync_external_printing_order_snapshot_impl(
external_order_id=payload['external_order_id'],
operator_user=request.user,
allow_reset_stateflow=payload.get('allow_reset_stateflow', False),
)
except ExternalPrintingOrderSnapshotSyncError as exc:
return Response(
{
'detail': str(exc),
'audit_id': exc.audit_id,
'external_order_id': payload['external_order_id'],
},
status=exc.status_code,
)
return Response(
{
'detail': '外部订单快照同步成功',
**result,
},
status=status.HTTP_200_OK,
)
class PrintingJobBatchAddParametersRequestSerializer(serializers.Serializer):
"""批量补充参数请求序列化器"""
printing_job_ids = serializers.ListField(