fix: 转交通知中product_sn始终为空 — product查询移到通知循环之前
根因: transfer_task中 product_result 查询在通知创建循环之后
通知内容 product_sn 引用未初始化的 product 变量 → 始终为空字符串
修复: 将 product 查询提前到 flush() 之后、通知循环之前
This commit is contained in:
@ -816,6 +816,13 @@ async def transfer_task(
|
|||||||
# 批量 flush 以生成 ID
|
# 批量 flush 以生成 ID
|
||||||
await db.flush()
|
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:
|
for nt in created_tasks:
|
||||||
await _create_task_log(
|
await _create_task_log(
|
||||||
db, nt.id,
|
db, nt.id,
|
||||||
@ -826,12 +833,6 @@ async def transfer_task(
|
|||||||
)
|
)
|
||||||
# 🔔 通知:新任务派发
|
# 🔔 通知:新任务派发
|
||||||
if nt.assignee_id:
|
if nt.assignee_id:
|
||||||
product_sn = ""
|
|
||||||
try:
|
|
||||||
if product:
|
|
||||||
product_sn = product.serial_number or ""
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
db.add(Notification(
|
db.add(Notification(
|
||||||
user_id=nt.assignee_id,
|
user_id=nt.assignee_id,
|
||||||
title=f"🟢 新任务派发",
|
title=f"🟢 新任务派发",
|
||||||
@ -841,10 +842,6 @@ async def transfer_task(
|
|||||||
))
|
))
|
||||||
|
|
||||||
# --- 更新 Product 的 current_location_id ---
|
# --- 更新 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 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
|
||||||
|
|||||||
Reference in New Issue
Block a user