产品宏观状态自动同步: create_task/transfer_task/spawn_subtask均更新overall_status
This commit is contained in:
@ -180,9 +180,17 @@ async def get_top_level_tasks(db: AsyncSession, product_id: uuid.UUID) -> list[T
|
|||||||
|
|
||||||
|
|
||||||
async def create_task(db: AsyncSession, data: TaskCreate) -> TaskResponse:
|
async def create_task(db: AsyncSession, data: TaskCreate) -> TaskResponse:
|
||||||
"""创建任务"""
|
"""创建任务,并同步产品宏观状态"""
|
||||||
task = Task(**data.model_dump())
|
task = Task(**data.model_dump())
|
||||||
db.add(task)
|
db.add(task)
|
||||||
|
|
||||||
|
# 同步产品宏观状态
|
||||||
|
if data.task_name:
|
||||||
|
product_result = await db.execute(select(Product).where(Product.id == data.product_id))
|
||||||
|
product = product_result.scalar_one_or_none()
|
||||||
|
if product:
|
||||||
|
product.overall_status = "在库" if "virtual_warehouse" in data.task_name else data.task_name
|
||||||
|
|
||||||
await db.commit()
|
await db.commit()
|
||||||
await db.refresh(task)
|
await db.refresh(task)
|
||||||
return _to_response(task)
|
return _to_response(task)
|
||||||
@ -284,6 +292,12 @@ async def spawn_subtask(
|
|||||||
db.add(child)
|
db.add(child)
|
||||||
await db.flush()
|
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
|
||||||
|
|
||||||
await _create_task_log(db, child.id, action_type="create", operator_id=operator_id,
|
await _create_task_log(db, child.id, action_type="create", operator_id=operator_id,
|
||||||
remark=f"协助分支(由「{task.task_name}」派发,分配给 {data.assignee_id})")
|
remark=f"协助分支(由「{task.task_name}」派发,分配给 {data.assignee_id})")
|
||||||
await db.commit()
|
await db.commit()
|
||||||
@ -587,8 +601,10 @@ async def transfer_task(
|
|||||||
if product:
|
if product:
|
||||||
if has_warehouse and not real_branches:
|
if has_warehouse and not real_branches:
|
||||||
product.current_location_id = VIRTUAL_WAREHOUSE
|
product.current_location_id = VIRTUAL_WAREHOUSE
|
||||||
|
product.overall_status = "在库"
|
||||||
elif real_branches:
|
elif real_branches:
|
||||||
product.current_location_id = real_branches[0][1]
|
product.current_location_id = real_branches[0][1]
|
||||||
|
product.overall_status = real_branches[0][0]
|
||||||
|
|
||||||
await db.commit()
|
await db.commit()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user