修复: 驳回返工任务追溯上一环转交人 — parent.assignee → TaskLog.operator_id 三层兜底

This commit is contained in:
2026-08-05 16:03:33 +08:00
parent 7810097b39
commit 4f14a40bd9

View File

@ -302,18 +302,31 @@ async def reject_task(
remark=f"品质驳回: {request.reason}",
)
# --- 2. 确定返工任务的负责人(上一道工序的负责人) ---
# --- 2. 确定返工任务的负责人(追溯上一道工序的转交人) ---
rework_assignee_id: str | None = None
if task.parent_task_id:
# 有父任务:查父任务的 assignee
# 有父任务:返工给父任务的负责人(即上一环的转交人 A)
parent_result = await db.execute(
select(Task).where(Task.id == task.parent_task_id)
)
parent_task = parent_result.scalar_one_or_none()
if parent_task:
rework_assignee_id = parent_task.assignee_id
else:
# 无父任务(顶层):返工给自己
if not rework_assignee_id:
# 无父任务(顶层转交):从任务日志追溯创建人(转交发起者 A)
log_result = await db.execute(
select(TaskLog).where(
TaskLog.task_id == task_id,
TaskLog.action_type == "create",
).order_by(TaskLog.created_at.asc()).limit(1)
)
create_log = log_result.scalar_one_or_none()
if create_log and create_log.operator_id:
rework_assignee_id = create_log.operator_id
if not rework_assignee_id:
# 最后兜底:用当前任务的负责人(通常不应该走到这里)
rework_assignee_id = task.assignee_id
# --- 3. 创建返工任务 ---