fix(透视表): 在库按设备实际位置判断,修复数量不匹配

- 之前按最新主任务 task_name='在库' 判断,漏掉实际在库但无在库任务的历史设备
- 改为 current_location_id='virtual_warehouse' → 在库(生产完成)
- 其他设备按最新主任务工序归属(活跃/完成态都归该工序)
- 在库数量与实际在库设备一致
This commit is contained in:
2026-08-31 17:24:38 +08:00
parent beeee57b75
commit 0fc061728c

View File

@ -638,6 +638,7 @@ async def get_wip_matrix(
Task.task_name, Task.task_name,
Task.assignee_id, Task.assignee_id,
Task.created_at, Task.created_at,
Product.current_location_id,
) )
.join(Task, Task.product_id == Product.id) .join(Task, Task.product_id == Product.id)
.where( .where(
@ -653,7 +654,7 @@ async def get_wip_matrix(
# 每台设备 → (spec, 当前工序/负责人, 当前负责人ID) # 每台设备 → (spec, 当前工序/负责人, 当前负责人ID)
device_cur: dict[str, tuple] = {} device_cur: dict[str, tuple] = {}
seen: set[str] = set() seen: set[str] = set()
for pid, spec, task_name, assignee, created in rows: for pid, spec, task_name, assignee, created, loc in rows:
if pid in seen: if pid in seen:
continue continue
seen.add(pid) seen.add(pid)
@ -667,8 +668,12 @@ async def get_wip_matrix(
continue continue
if dimension == "task_name": if dimension == "task_name":
# 设备当前工序 = 最新主任务的工序名(不区分状态,不强制完成态归在库 # 🔧 在库按设备实际位置判断virtual_warehouse → 在库(生产完成
key = task_name or "" # 否则按最新主任务工序名(活跃/完成态都归该工序)
if loc == "virtual_warehouse":
key = "在库"
else:
key = task_name or ""
else: else:
key = assignee or "未分配" key = assignee or "未分配"
device_cur[pid] = (spec or "未知型号", key, assignee or "") device_cur[pid] = (spec or "未知型号", key, assignee or "")