forked from erp-dev/erp
fix: added merchant_id to printing_order and plate_order
This commit is contained in:
@@ -1,8 +1,14 @@
|
||||
from __future__ import annotations
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from django.db import models
|
||||
from django.contrib.auth import get_user_model
|
||||
from flower.common import ModelBase
|
||||
from basic_info import models as basic_models
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from printing.models import PrintingJob
|
||||
|
||||
User = get_user_model()
|
||||
|
||||
|
||||
@@ -138,7 +144,7 @@ class SalesItem(ModelBase):
|
||||
def __str__(self):
|
||||
return f'{self.name} x {self.quantity} {self.get_unit_display()}'
|
||||
|
||||
def get_printing_job(self):
|
||||
def get_printing_job(self) -> PrintingJob | None:
|
||||
"""
|
||||
获取关联的 PrintingJob 实例
|
||||
|
||||
@@ -150,10 +156,10 @@ class SalesItem(ModelBase):
|
||||
try:
|
||||
from printing.models import PrintingJob
|
||||
return PrintingJob.objects.get(id=self.printing_job_id)
|
||||
except Exception:
|
||||
except PrintingJob.DoesNotExist:
|
||||
return None
|
||||
|
||||
def get_customer(self):
|
||||
def get_customer(self) -> basic_models.Customer | None:
|
||||
"""
|
||||
获取关联的 Customer 实例
|
||||
|
||||
|
||||
39
shipment/services.py
Normal file
39
shipment/services.py
Normal 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')
|
||||
Reference in New Issue
Block a user