修复: MissingGreenlet_product访问try/catch + spawn_subtask不再覆盖overall_status
This commit is contained in:
@ -93,11 +93,19 @@ async def _get_task_with_children_recursive(db: AsyncSession, task_id: uuid.UUID
|
||||
|
||||
def _to_response(task: Task) -> TaskResponse:
|
||||
"""将 Task ORM 对象转为递归 TaskResponse"""
|
||||
product_sn = ""
|
||||
product_material = ""
|
||||
try:
|
||||
if task.product:
|
||||
product_sn = task.product.serial_number or ""
|
||||
product_material = (task.product.material_name or task.product.material_id or "")
|
||||
except Exception:
|
||||
pass
|
||||
return TaskResponse(
|
||||
id=task.id,
|
||||
product_id=task.product_id,
|
||||
product_sn=task.product.serial_number if task.product else "",
|
||||
product_material=task.product.material_name or task.product.material_id or "" if task.product else "",
|
||||
product_sn=product_sn,
|
||||
product_material=product_material,
|
||||
parent_task_id=task.parent_task_id,
|
||||
task_name=task.task_name,
|
||||
assignee_id=task.assignee_id,
|
||||
@ -295,11 +303,7 @@ async def spawn_subtask(
|
||||
db.add(child)
|
||||
await db.flush()
|
||||
|
||||
# 同步产品宏观状态
|
||||
product_result = await db.execute(select(Product).where(Product.id == task.product_id))
|
||||
product = product_result.scalar_one_or_none()
|
||||
if product and data.task_name:
|
||||
product.overall_status = "在库" if "virtual_warehouse" in data.task_name else data.task_name
|
||||
# 协助分支不改变产品宏观状态(只有主分支影响 overall_status)
|
||||
|
||||
await _create_task_log(db, child.id, action_type="create", operator_id=operator_id,
|
||||
remark=f"协助分支(由「{task.task_name}」派发,分配给 {data.assignee_id})")
|
||||
|
||||
Reference in New Issue
Block a user