1
0
forked from erp-dev/erp

feat: support pre_sales_order convert to sales_order api

This commit is contained in:
2026-02-02 15:58:29 +08:00
parent 2572c5aab4
commit fb93582b06
13 changed files with 379 additions and 7 deletions

View File

@@ -279,6 +279,41 @@ class PreSalesOrderDetailView(StockChangeViewMixin, views.APIView):
return Response(status=status.HTTP_204_NO_CONTENT)
class PreSalesOrderConvertToSalesOrderView(StockChangeViewMixin, views.APIView):
permission_classes = [IsAuthenticated]
def post(self, request, pk: int):
if not self.check_employee_permission(request):
return self.permission_error_response('无权限访问')
merchant = request.user.employee.merchant
employee = request.user.employee
try:
sales_order = pre_order_services.convert_pre_sales_order_to_sales_order(
merchant=merchant,
pre_sales_order_id=pk,
operator=employee,
created_by=request.user,
)
except PermissionError as exc:
return Response({'error': str(exc)}, status=status.HTTP_403_FORBIDDEN)
except business_models.PreSalesOrder.DoesNotExist:
return self.not_found_response('预销售单不存在')
except ValueError as exc:
return Response({'error': str(exc)}, status=status.HTTP_400_BAD_REQUEST)
return Response(
{
'id': sales_order.id,
'human_id': sales_order.human_id,
'status': sales_order.status,
'message': '预销售单已转换为销售单,等待审批',
},
status=status.HTTP_201_CREATED,
)
class PreSalesOrderItemAllocationView(StockChangeViewMixin, views.APIView):
permission_classes = [IsAuthenticated]
@@ -336,5 +371,8 @@ class PreSalesOrderItemAllocationDetailView(StockChangeViewMixin, views.APIView)
except business_models.AllocationRecord.DoesNotExist:
return self.not_found_response('配货记录不存在')
updated = allocation_services.cancel_allocation_record(record=record)
updated = allocation_services.cancel_allocation_record_with_unfreeze(
record=record,
cancelled_by=request.user,
)
return Response(AllocationRecordSerializer(updated).data, status=status.HTTP_200_OK)