1
0
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:
2026-04-09 17:35:14 +08:00
parent 76ea445880
commit 646dbe7f18
27 changed files with 1122 additions and 13 deletions

View File

@@ -253,8 +253,8 @@ def on_printing_order_created(sender, **kwargs):
- 消息字段(中文):
- 印染订单ID / human_id
- 创建时间
- 发送者(优先 created_by.employee.name / created_by.username
- 客户、面料、出货日期(可选字段,缺省展示为 '-'
- 发送者(优先 created_by.employee.name / created_by.username
- 客户、面料、出货日期(可选字段,缺省展示为 '-'
"""
# 测试环境默认关闭,避免单测出网/刷屏
if not getattr(settings, "PRINTING_ORDER_CREATED_WECOM_NOTIFY_ENABLED", True):
@@ -336,3 +336,44 @@ def on_printing_order_created(sender, **kwargs):
# 在事务提交后再发送,避免事务回滚但通知已发出
transaction.on_commit(_send_wecom)
def on_printing_job_production_completed(sender, **kwargs):
"""
PrintingJob 被显式标记为完成生产后的处理。
当前通过 Celery task 异步发送企业微信通知,避免阻塞主流程。
"""
if not getattr(settings, "PRINTING_JOB_PRODUCTION_COMPLETED_WECOM_NOTIFY_ENABLED", True):
return
if getattr(settings, "TESTING", False):
return
job = kwargs.get("instance")
triggered_by = kwargs.get("triggered_by")
if job is None:
logger.warning(
"[printing.handlers] printing_job_production_completed 信号缺少 instance跳过通知"
)
return
logger.info(
"[printing.handlers] 收到 printing_job_production_completed 信号: sender=%s, job_id=%s",
sender,
getattr(job, "id", None),
)
def _enqueue_task():
try:
from printing.tasks import notify_printing_job_production_completed_wecom
notify_printing_job_production_completed_wecom.delay(
printing_job_id=job.id,
triggered_by_id=getattr(triggered_by, "id", None),
)
except Exception:
logger.exception(
"[printing.handlers] 投递 notify_printing_job_production_completed_wecom task 失败(已忽略,不影响主流程)"
)
transaction.on_commit(_enqueue_task)