1
0
forked from erp-dev/erp

fix: appversions

This commit is contained in:
2026-07-11 00:05:05 +08:00
parent 48e4782e1e
commit e91d06e4b6
26 changed files with 2582 additions and 19 deletions

View File

@@ -12,7 +12,7 @@ from rest_framework.views import APIView
from django.utils.dateparse import parse_date, parse_datetime
from flower.viewsets import LimitedLimitOffsetPagination
from shipment.models import Shipment, ShipmentDelivery, ShipmentDeliveryStatus, ShipmentStatus
from shipment.models import SalesItem, Shipment, ShipmentDelivery, ShipmentDeliveryStatus, ShipmentStatus
from .serializers import (
SalesItemDetailSerializer,
@@ -26,6 +26,7 @@ from .serializers import (
ShipmentDeliverySerializer,
ShipmentDeliveryStatusUpdateSerializer,
ShipmentDeliveryUpdateSerializer,
ShipmentPrintingJobSummarySerializer,
ShipmentSerializer,
ShipmentCreateNormalSerializer,
ShipmentCreateExternalSerializer,
@@ -97,6 +98,26 @@ def _build_sales_item_serializer_context(items):
}
def _get_printing_jobs_for_shipment_ids(*, merchant, shipment_ids):
from printing.models import PrintingJob
printing_job_ids = (
SalesItem.objects.filter(
merchant=merchant,
shipment_id__in=shipment_ids,
delete_at__isnull=True,
printing_job_id__isnull=False,
)
.values_list("printing_job_id", flat=True)
.distinct()
)
return (
PrintingJob.objects.filter(id__in=printing_job_ids)
.select_related("printing_order", "printing_order__customer")
.order_by("id")
)
class ShipmentListCreateView(ListModelMixin, GenericAPIView):
"""
出货单:查询列表 / 创建
@@ -417,6 +438,40 @@ class ShipmentStatusUpdateView(APIView):
return self.patch(request, pk=pk)
class ShipmentPrintingJobListView(GenericAPIView):
permission_classes = [IsAuthenticated]
serializer_class = ShipmentPrintingJobSummarySerializer
pagination_class = LimitedLimitOffsetPagination
def get_shipment_queryset(self):
qs = Shipment.objects.all().select_related("merchant")
user = self.request.user
if getattr(user, "is_superuser", False):
return qs
emp = getattr(user, "employee", None)
merchant = getattr(emp, "merchant", None) if emp else None
if not merchant:
return Shipment.objects.none()
return qs.filter(merchant=merchant)
def get(self, request, pk: int):
shipment = self.get_shipment_queryset().filter(id=pk).first()
if shipment is None:
return Response({"detail": "Not found."}, status=status.HTTP_404_NOT_FOUND)
queryset = _get_printing_jobs_for_shipment_ids(
merchant=shipment.merchant,
shipment_ids=[shipment.id],
)
page = self.paginate_queryset(queryset)
if page is not None:
serializer = self.get_serializer(page, many=True)
return self.get_paginated_response(serializer.data)
serializer = self.get_serializer(queryset, many=True)
return Response(serializer.data)
class ShipmentDeliveryListCreateView(ListModelMixin, GenericAPIView):
"""
送货单:查询列表 / 创建
@@ -435,6 +490,7 @@ class ShipmentDeliveryListCreateView(ListModelMixin, GenericAPIView):
).prefetch_related(
"shipments",
"shipments__customer",
"shipments__customer_address",
)
user = self.request.user
@@ -489,6 +545,7 @@ class ShipmentDeliveryListCreateView(ListModelMixin, GenericAPIView):
).prefetch_related(
"shipments",
"shipments__customer",
"shipments__customer_address",
).get(id=delivery.id)
return Response(
@@ -652,7 +709,11 @@ class ShipmentDeliveryByPrintingOrderView(GenericAPIView):
shipments__items__delete_at__isnull=True,
)
.select_related("merchant", "created_by", "operator", "cancelled_by")
.prefetch_related("shipments", "shipments__customer")
.prefetch_related(
"shipments",
"shipments__customer",
"shipments__customer_address",
)
)
queryset = self._apply_filters(queryset)
@@ -682,6 +743,7 @@ class ShipmentDeliveryDetailView(RetrieveModelMixin, GenericAPIView):
).prefetch_related(
"shipments",
"shipments__customer",
"shipments__customer_address",
)
user = self.request.user
@@ -744,6 +806,41 @@ class ShipmentDeliveryDetailView(RetrieveModelMixin, GenericAPIView):
return Response(status=status.HTTP_204_NO_CONTENT)
class ShipmentDeliveryPrintingJobListView(GenericAPIView):
permission_classes = [IsAuthenticated]
serializer_class = ShipmentPrintingJobSummarySerializer
pagination_class = LimitedLimitOffsetPagination
def get_delivery_queryset(self):
qs = ShipmentDelivery.objects.all().select_related("merchant")
user = self.request.user
if getattr(user, "is_superuser", False):
return qs
emp = getattr(user, "employee", None)
merchant = getattr(emp, "merchant", None) if emp else None
if not merchant:
return ShipmentDelivery.objects.none()
return qs.filter(merchant=merchant)
def get(self, request, pk: int):
delivery = self.get_delivery_queryset().filter(id=pk).first()
if delivery is None:
return Response({"detail": "Not found."}, status=status.HTTP_404_NOT_FOUND)
shipment_ids = delivery.shipments.values_list("id", flat=True)
queryset = _get_printing_jobs_for_shipment_ids(
merchant=delivery.merchant,
shipment_ids=shipment_ids,
)
page = self.paginate_queryset(queryset)
if page is not None:
serializer = self.get_serializer(page, many=True)
return self.get_paginated_response(serializer.data)
serializer = self.get_serializer(queryset, many=True)
return Response(serializer.data)
class ShipmentDeliveryStatusUpdateView(APIView):
"""
修改送货单状态
@@ -787,6 +884,7 @@ class ShipmentDeliveryStatusUpdateView(APIView):
).prefetch_related(
"shipments",
"shipments__customer",
"shipments__customer_address",
).get(id=delivery.id)
return Response(
@@ -837,6 +935,7 @@ class ShipmentDeliveryCancelView(APIView):
).prefetch_related(
"shipments",
"shipments__customer",
"shipments__customer_address",
).get(id=delivery.id)
return Response(
@@ -888,6 +987,7 @@ class ShipmentDeliveryBindShipmentsView(APIView):
).prefetch_related(
"shipments",
"shipments__customer",
"shipments__customer_address",
).get(id=delivery.id)
return Response(