diff --git a/backend/app/services/task_service.py b/backend/app/services/task_service.py index eaf2535..06d662b 100644 --- a/backend/app/services/task_service.py +++ b/backend/app/services/task_service.py @@ -816,6 +816,13 @@ async def transfer_task( # 批量 flush 以生成 ID await db.flush() + # 提前查询产品(通知需要 product_sn) + product_result = await db.execute( + select(Product).where(Product.id == task.product_id) + ) + product = product_result.scalar_one_or_none() + product_sn = product.serial_number if product else "" + for nt in created_tasks: await _create_task_log( db, nt.id, @@ -826,12 +833,6 @@ async def transfer_task( ) # 🔔 通知:新任务派发 if nt.assignee_id: - product_sn = "" - try: - if product: - product_sn = product.serial_number or "" - except Exception: - pass db.add(Notification( user_id=nt.assignee_id, title=f"🟢 新任务派发", @@ -841,10 +842,6 @@ async def transfer_task( )) # --- 更新 Product 的 current_location_id --- - product_result = await db.execute( - select(Product).where(Product.id == task.product_id) - ) - product = product_result.scalar_one_or_none() if product: if has_warehouse and not real_branches: product.current_location_id = VIRTUAL_WAREHOUSE