修复: create_task同步current_location_id到接收人 + receive_task兜底同步产品位置

This commit is contained in:
2026-08-06 09:12:07 +08:00
parent f3fb000bda
commit eb52e2fd48

View File

@ -184,12 +184,15 @@ async def create_task(db: AsyncSession, data: TaskCreate) -> TaskResponse:
task = Task(**data.model_dump())
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_result = await db.execute(select(Product).where(Product.id == data.product_id))
product = product_result.scalar_one_or_none()
if product:
if data.task_name:
product.overall_status = "在库" if "virtual_warehouse" in data.task_name else data.task_name
# 派发给人 → 产品离开仓库
if data.assignee_id and data.assignee_id != VIRTUAL_WAREHOUSE:
product.current_location_id = data.assignee_id
await db.commit()
await db.refresh(task)
@ -369,6 +372,12 @@ async def receive_task(
remark=remark or f"操作员确认接收任务「{task.task_name}",
)
# 接收时同步产品位置到接收人
product_result = await db.execute(select(Product).where(Product.id == task.product_id))
product = product_result.scalar_one_or_none()
if product and task.assignee_id:
product.current_location_id = task.assignee_id
await db.commit()
await db.refresh(task)