From 3a07f1a272eca30eb1b0b1ff039a78e885f8961f Mon Sep 17 00:00:00 2001 From: yueli Date: Mon, 31 Aug 2026 10:28:22 +0800 Subject: [PATCH] =?UTF-8?q?fix(bom):=20BOM=20=E8=AF=A6=E6=83=85=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E6=94=B9=E4=B8=BA=20LEFT=20JOIN=EF=BC=8C=E5=AD=90?= =?UTF-8?q?=E4=BB=B6=E7=89=A9=E6=96=99=E8=A2=AB=E5=88=A0=E5=90=8E=E4=BB=8D?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E7=88=B6=E4=BB=B6=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - get_bom_detail 使用 outerjoin 替代 join - 子件物料被删除后 child_name 显示 [已删除物料] 而非误报 BOM 不存在 - 修复按 BOM 出库时因子件删除导致 404 BOM 不存在 --- inventory-backend/app/services/bom_service.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/inventory-backend/app/services/bom_service.py b/inventory-backend/app/services/bom_service.py index 2941fb3..d6e0cf0 100644 --- a/inventory-backend/app/services/bom_service.py +++ b/inventory-backend/app/services/bom_service.py @@ -293,7 +293,8 @@ class BomService: BomTable, MaterialBase.name.label('child_name'), MaterialBase.spec_model.label('child_spec') - ).join( + ).outerjoin( + # ★ LEFT JOIN:子件物料被删除后仍返回父件 BOM 结构,避免误报 "BOM 不存在" MaterialBase, BomTable.child_id == MaterialBase.id ).filter( BomTable.bom_no == bom_no @@ -322,7 +323,7 @@ class BomService: for bom, child_name, child_spec in rows: children.append({ 'child_id': bom.child_id, - 'child_name': child_name, + 'child_name': child_name or '[已删除物料]', 'child_spec': child_spec or '', 'dosage': float(bom.dosage) if bom.dosage else 0.0, 'remark': bom.remark or ''