diff --git a/backend/app/services/task_service.py b/backend/app/services/task_service.py index ccfec42..6891320 100644 --- a/backend/app/services/task_service.py +++ b/backend/app/services/task_service.py @@ -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: - """创建任务""" + """创建任务,并同步产品宏观状态""" 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.overall_status = "在库" if "virtual_warehouse" in data.task_name else data.task_name + await db.commit() await db.refresh(task) return _to_response(task) @@ -284,6 +292,12 @@ 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 + await _create_task_log(db, child.id, action_type="create", operator_id=operator_id, remark=f"协助分支(由「{task.task_name}」派发,分配给 {data.assignee_id})") await db.commit() @@ -587,8 +601,10 @@ async def transfer_task( if product: if has_warehouse and not real_branches: product.current_location_id = VIRTUAL_WAREHOUSE + product.overall_status = "在库" elif real_branches: product.current_location_id = real_branches[0][1] + product.overall_status = real_branches[0][0] await db.commit()