try_complete 在无活跃任务时也会把已配置打成已完成;清空全部后再添加会踩中。 现要求至少有一条活跃任务且全部完成后才自动完成,并强制全量重建时清理旧批次,前后端均校验批次须含检测项目。 Co-authored-by: Cursor <cursoragent@cursor.com>
19 lines
646 B
Python
19 lines
646 B
Python
"""质检工单自动完成判定(无 DB 依赖,供 CRUD 与单测共用)。"""
|
|
|
|
|
|
def can_auto_complete_work_order(
|
|
*, status: str, active_task_count: int, pending_task_count: int
|
|
) -> bool:
|
|
"""仅当工单为已配置、存在活跃任务且全部已完成时,才可标为已完成。
|
|
|
|
活跃任务数为 0 时不得完成:调整检测清空后重配若尚未产生任务,
|
|
否则会把「已配置」误标为「已完成」。
|
|
"""
|
|
if (status or "").strip() != "ypz":
|
|
return False
|
|
if active_task_count <= 0:
|
|
return False
|
|
if pending_task_count > 0:
|
|
return False
|
|
return True
|