1
0
forked from erp-dev/erp

feat: human_id for all objects in business module

This commit is contained in:
2026-06-25 13:41:17 +08:00
parent 70b3a0d246
commit e8bf4b5e49
14 changed files with 305 additions and 22 deletions

View File

@@ -12,6 +12,7 @@ from rest_framework.response import Response
from rest_framework.views import APIView
from basic_info import models as basic_models
from business import models as business_models
from printing import models as printing_models
from api_v1.tasks import (
ExternalPrintingOrderSnapshotSyncError,
@@ -180,6 +181,73 @@ class PrintingJobByCustomerView(APIView):
return Response(serializer.data)
class PrintingOrderWithoutSalesOrderSerializer(serializers.ModelSerializer):
"""未关联非作废销售单的印染订单列表序列化器。"""
customer_name = serializers.CharField(source='customer.name', read_only=True)
class Meta:
model = printing_models.PrintingOrder
fields = [
'id',
'human_id',
'external_order_id',
'customer',
'customer_name',
'fabric',
'width',
'is_urgent',
'is_invalid',
'outgoing_date',
'created_at',
'updated_at',
]
read_only_fields = fields
class PrintingOrderWithoutSalesOrderView(APIView):
"""
按客户查询尚未关联非作废销售单的印染订单。
关联路径:
PrintingOrder -> PrintingJob -> SalesOrderItem -> SalesOrder
已作废 SalesOrder 不计为有效关联。
"""
serializer_class = PrintingOrderWithoutSalesOrderSerializer
permission_classes = [permissions.IsAuthenticated, IsPrintingFactory]
def get(self, request):
customer_id = request.query_params.get('customer_id')
if not customer_id:
return Response({'detail': 'customer_id 为必填参数'}, status=status.HTTP_400_BAD_REQUEST)
try:
customer_id_int = int(customer_id)
except (TypeError, ValueError):
return Response({'detail': 'customer_id 必须为数字'}, status=status.HTTP_400_BAD_REQUEST)
merchant = request.user.employee.merchant
active_sales_order_items = business_models.SalesOrderItem.objects.filter(
printing_job__printing_order_id=OuterRef('pk'),
).exclude(
sales_order__status=business_models.SalesOrderStatusEnum.CANCELLED,
)
queryset = (
printing_models.PrintingOrder.objects
.select_related('customer')
.filter(customer_id=customer_id_int)
.filter(Q(merchant=merchant) | Q(merchant__isnull=True, customer__merchant=merchant))
.annotate(_has_active_sales_order=Exists(active_sales_order_items))
.filter(_has_active_sales_order=False)
.order_by('-created_at', '-id')
)
serializer = self.serializer_class(queryset, many=True)
return Response(serializer.data)
class PrintingJobBatchAdvancePreviewRequestSerializer(serializers.Serializer):
"""批量推进:预览/校验请求"""