fix(透视表): WIP 分布矩阵只统计主分支

- get_wip_matrix 过滤 parent_task_id IS NULL 或 TRANSFER/RECOVERY 的主线任务
- 排除 SPAWN 协助分支与返工任务,避免同一设备/工序重复计数
This commit is contained in:
2026-08-28 16:51:46 +08:00
parent 8c3c0c4d90
commit 0dcdb5dad7

View File

@ -613,6 +613,7 @@ async def get_wip_matrix(
"""生产分布透视表Y=规格型号X=人员 或 工序,单元格=设备数量。
覆盖全部任务状态(含已完成/在库),工序分布能看到「在库」(生产完成)。
只统计主分支parent_task_id IS NULL 或 TRANSFER/RECOVERY避免协助分支/返工重复计数。
since/until 按任务接手/创建时间过滤。
dimension:
@ -632,6 +633,13 @@ async def get_wip_matrix(
func.array_agg(func.distinct(Task.assignee_id)),
)
.join(Task, Task.product_id == Product.id)
# 🔧 只统计主分支(主线任务),排除 SPAWN 协助分支
.where(
or_(
Task.parent_task_id.is_(None),
Task.task_type.in_(["TRANSFER", "RECOVERY"]),
)
)
.group_by(Product.spec_model, dim_expr)
.order_by(Product.spec_model, dim_expr)
)