forked from erp-dev/erp
fin
This commit is contained in:
@@ -444,6 +444,9 @@ class PrintingJobFilterSet(django_filters.FilterSet):
|
||||
external_order_id = django_filters.CharFilter(
|
||||
field_name="printing_order__external_order_id", lookup_expr="icontains"
|
||||
)
|
||||
customer_name = django_filters.CharFilter(
|
||||
field_name="printing_order__customer__name", lookup_expr="icontains"
|
||||
)
|
||||
product = django_filters.NumberFilter()
|
||||
product_name = django_filters.CharFilter(
|
||||
field_name="product__name", lookup_expr="icontains"
|
||||
@@ -453,12 +456,30 @@ class PrintingJobFilterSet(django_filters.FilterSet):
|
||||
quantity_max = django_filters.NumberFilter(field_name="quantity", lookup_expr="lte")
|
||||
pieces_min = django_filters.NumberFilter(field_name="pieces", lookup_expr="gte")
|
||||
pieces_max = django_filters.NumberFilter(field_name="pieces", lookup_expr="lte")
|
||||
created_at_from = django_filters.CharFilter(method="filter_created_at_from")
|
||||
created_at_to = django_filters.CharFilter(method="filter_created_at_to")
|
||||
is_production_completed = django_filters.BooleanFilter()
|
||||
|
||||
class Meta:
|
||||
model = models.PrintingJob
|
||||
fields = ["printing_order", "product", "external_order_id", "is_production_completed"]
|
||||
|
||||
def filter_created_at_from(self, queryset, name, value):
|
||||
dt, _has_time = PrintingOrderFilterSet._parse_date_or_datetime(value)
|
||||
if dt is None:
|
||||
raise ValidationError("created_at_from 必须是日期或日期时间")
|
||||
return queryset.filter(created_at__gte=dt)
|
||||
|
||||
def filter_created_at_to(self, queryset, name, value):
|
||||
dt, has_time = PrintingOrderFilterSet._parse_date_or_datetime(value)
|
||||
if dt is None:
|
||||
raise ValidationError("created_at_to 必须是日期或日期时间")
|
||||
|
||||
if not has_time:
|
||||
return queryset.filter(created_at__lt=dt + timedelta(days=1))
|
||||
|
||||
return queryset.filter(created_at__lte=dt)
|
||||
|
||||
|
||||
class PrintingJobViewSet(CustomerVisibilityFilterMixin, LimitedModelViewSet):
|
||||
"""
|
||||
@@ -484,6 +505,7 @@ class PrintingJobViewSet(CustomerVisibilityFilterMixin, LimitedModelViewSet):
|
||||
查询参数:
|
||||
- printing_order: 印染订单ID
|
||||
- external_order_id: 外部订单编号(按所属订单模糊查询)
|
||||
- customer_name: 客户名称(按所属订单客户名称模糊查询)
|
||||
- product: 产品ID
|
||||
- product_name: 产品名称(模糊查询)
|
||||
- unit: 单位(模糊查询)
|
||||
@@ -491,6 +513,8 @@ class PrintingJobViewSet(CustomerVisibilityFilterMixin, LimitedModelViewSet):
|
||||
- quantity_max: 最大数量
|
||||
- pieces_min: 最小件数
|
||||
- pieces_max: 最大件数
|
||||
- created_at_from: 创建时间开始(支持 YYYY-MM-DD 或日期时间)
|
||||
- created_at_to: 创建时间结束(YYYY-MM-DD 会包含整天)
|
||||
- is_production_completed: 是否已标记完成生产(true/false)
|
||||
- search: 全文搜索(产品名称、单位、尺寸、备注)
|
||||
- ordering: 排序字段
|
||||
@@ -529,7 +553,7 @@ class PrintingJobViewSet(CustomerVisibilityFilterMixin, LimitedModelViewSet):
|
||||
if self.action in ["list", "retrieve"]:
|
||||
from business.models import SalesOrderItem, SalesOrderStatusEnum
|
||||
|
||||
queryset = queryset.select_related("printing_order", "product")
|
||||
queryset = queryset.select_related("printing_order", "printing_order__customer", "product")
|
||||
queryset = queryset.annotate(
|
||||
annotated_is_sales_order_bound=Exists(
|
||||
SalesOrderItem.objects.filter(
|
||||
|
||||
Reference in New Issue
Block a user