forked from erp-dev/erp
feat: added wecom notify when printing_job production was completed(new status) and shipment was created
This commit is contained in:
@@ -412,10 +412,11 @@ 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")
|
||||
is_production_completed = django_filters.BooleanFilter()
|
||||
|
||||
class Meta:
|
||||
model = models.PrintingJob
|
||||
fields = ["printing_order", "product", "external_order_id"]
|
||||
fields = ["printing_order", "product", "external_order_id", "is_production_completed"]
|
||||
|
||||
|
||||
class PrintingJobViewSet(CustomerVisibilityFilterMixin, LimitedModelViewSet):
|
||||
@@ -449,6 +450,7 @@ class PrintingJobViewSet(CustomerVisibilityFilterMixin, LimitedModelViewSet):
|
||||
- quantity_max: 最大数量
|
||||
- pieces_min: 最小件数
|
||||
- pieces_max: 最大件数
|
||||
- is_production_completed: 是否已标记完成生产(true/false)
|
||||
- search: 全文搜索(产品名称、单位、尺寸、备注)
|
||||
- ordering: 排序字段
|
||||
|
||||
@@ -537,6 +539,60 @@ class PrintingJobViewSet(CustomerVisibilityFilterMixin, LimitedModelViewSet):
|
||||
serializer = self.get_serializer(instance)
|
||||
return Response(serializer.data)
|
||||
|
||||
@action(detail=False, methods=["post"], url_path="mark-production-completed")
|
||||
def mark_production_completed(self, request):
|
||||
"""
|
||||
显式标记印染任务已完成生产。
|
||||
|
||||
请求体:
|
||||
{
|
||||
"printing_job_id": 123
|
||||
}
|
||||
"""
|
||||
printing_job_id = request.data.get("printing_job_id")
|
||||
if not printing_job_id:
|
||||
return Response(
|
||||
{"detail": "printing_job_id 不能为空"},
|
||||
status=status.HTTP_400_BAD_REQUEST,
|
||||
)
|
||||
|
||||
user = request.user
|
||||
merchant = None
|
||||
if hasattr(user, "employee") and user.employee and user.employee.merchant:
|
||||
merchant = user.employee.merchant
|
||||
|
||||
if merchant is None:
|
||||
return Response(
|
||||
{"detail": "当前用户未关联商户"},
|
||||
status=status.HTTP_403_FORBIDDEN,
|
||||
)
|
||||
|
||||
try:
|
||||
job = models.PrintingJob.objects.get(pk=printing_job_id)
|
||||
except models.PrintingJob.DoesNotExist:
|
||||
return Response(
|
||||
{"detail": "PrintingJob 不存在"},
|
||||
status=status.HTTP_404_NOT_FOUND,
|
||||
)
|
||||
|
||||
job_merchant = getattr(job, "merchant", None)
|
||||
if job_merchant is None and getattr(job, "printing_order", None):
|
||||
job_merchant = getattr(job.printing_order, "merchant", None)
|
||||
|
||||
if job_merchant and job_merchant.id != merchant.id:
|
||||
return Response(
|
||||
{"detail": "您不能操作其他商户的 PrintingJob"},
|
||||
status=status.HTTP_403_FORBIDDEN,
|
||||
)
|
||||
|
||||
from .services import PrintingJobService
|
||||
|
||||
PrintingJobService.make_printing_job_production_completed(
|
||||
job,
|
||||
triggered_by=user,
|
||||
)
|
||||
return Response({"message": "OK"}, status=status.HTTP_200_OK)
|
||||
|
||||
def destroy(self, request, *args, **kwargs):
|
||||
"""禁用删除操作"""
|
||||
return Response(
|
||||
|
||||
Reference in New Issue
Block a user