1
0
forked from erp-dev/erp

fix: added merchant_id to printing_order and plate_order

This commit is contained in:
2026-01-14 14:26:03 +08:00
parent 3e75328156
commit fae667c965
20 changed files with 1049 additions and 17 deletions

39
shipment/services.py Normal file
View File

@@ -0,0 +1,39 @@
"""
Shipment 模块业务逻辑层
"""
from __future__ import annotations
from django.db.models import QuerySet
from shipment.models import SalesItem
def get_sales_items_by_printing_order(
printing_order_id: int,
include_already_has_shipment: bool = False,
) -> QuerySet[SalesItem]:
"""
通过生产订单ID查询对应的销售品
Args:
printing_order_id: 生产订单ID
include_already_has_shipment: 是否包含已关联出货单的销售品,默认为 False
Returns:
SalesItem 查询集
"""
from printing.models import PrintingJob
# 1. 获取该生产订单下所有 PrintingJob 的 ID
job_ids = PrintingJob.objects.filter(
printing_order_id=printing_order_id
).values_list('id', flat=True)
# 2. 查询 SalesItem过滤 printing_job_id 在这些 job_ids 中
queryset = SalesItem.objects.filter(printing_job_id__in=list(job_ids))
# 3. 根据参数决定是否过滤已出货的销售品
if not include_already_has_shipment:
queryset = queryset.filter(shipment__isnull=True)
return queryset.select_related('shipment').order_by('id')