From 30ab1c186ca2eb363960d737f0f6b6dc5c068c3c Mon Sep 17 00:00:00 2001 From: DXC Date: Tue, 7 Apr 2026 16:41:53 +0800 Subject: [PATCH] fix: filter zero quantity items in inventory export and add batch/sn traceability to outbound record details --- .../app/services/inbound/base_service.py | 6 ++-- .../app/services/outbound_service.py | 33 +++++++++++-------- inventory-web/src/views/outbound/index.vue | 1 + 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/inventory-backend/app/services/inbound/base_service.py b/inventory-backend/app/services/inbound/base_service.py index 4cb8d01..84ff6cc 100644 --- a/inventory-backend/app/services/inbound/base_service.py +++ b/inventory-backend/app/services/inbound/base_service.py @@ -636,7 +636,7 @@ class MaterialBaseService: # 2.1 采购库存 (StockBuy) query_buy = db.session.query(StockBuy, MaterialBase).join( MaterialBase, StockBuy.base_id == MaterialBase.id - ) + ).filter(StockBuy.stock_quantity > 0) for cond in filter_conditions: query_buy = query_buy.filter(cond) list_buy = query_buy.all() @@ -644,7 +644,7 @@ class MaterialBaseService: # 2.2 半成品库存 (StockSemi) query_semi = db.session.query(StockSemi, MaterialBase).join( MaterialBase, StockSemi.base_id == MaterialBase.id - ) + ).filter(StockSemi.stock_quantity > 0) for cond in filter_conditions: query_semi = query_semi.filter(cond) list_semi = query_semi.all() @@ -652,7 +652,7 @@ class MaterialBaseService: # 2.3 成品库存 (StockProduct) query_product = db.session.query(StockProduct, MaterialBase).join( MaterialBase, StockProduct.base_id == MaterialBase.id - ) + ).filter(StockProduct.stock_quantity > 0) for cond in filter_conditions: query_product = query_product.filter(cond) list_product = query_product.all() diff --git a/inventory-backend/app/services/outbound_service.py b/inventory-backend/app/services/outbound_service.py index 2467cc0..50f27b7 100644 --- a/inventory-backend/app/services/outbound_service.py +++ b/inventory-backend/app/services/outbound_service.py @@ -403,11 +403,12 @@ class OutboundService: 'items': [] } - # --- 查询物品详细信息 (名称, 规格, 类型, 类别) --- + # --- 查询物品详细信息 (名称, 规格, 类型, 类别, 批号/SN) --- item_name = "未知物品" item_spec = "" item_cat = "" item_type = "" + batch_sn = "-" ModelClass = model_map.get(d.source_table) if ModelClass and d.stock_id: @@ -415,18 +416,21 @@ class OutboundService: # 生产环境建议优化为预加载或批量查询 try: stock_item = ModelClass.query.get(d.stock_id) - if stock_item and stock_item.base: - item_name = stock_item.base.name - item_spec = stock_item.base.spec_model - item_cat = stock_item.base.category - item_type = stock_item.base.material_type - elif stock_item and hasattr(stock_item, 'base_id') and stock_item.base_id: - base_info = MaterialBase.query.get(stock_item.base_id) - if base_info: - item_name = base_info.name - item_spec = base_info.spec_model - item_cat = base_info.category - item_type = base_info.material_type + if stock_item: + # 获取批号/序列号用于追溯 + batch_sn = getattr(stock_item, 'batch_number', None) or getattr(stock_item, 'serial_number', None) or '-' + if stock_item.base: + item_name = stock_item.base.name + item_spec = stock_item.base.spec_model + item_cat = stock_item.base.category + item_type = stock_item.base.material_type + elif stock_item and hasattr(stock_item, 'base_id') and stock_item.base_id: + base_info = MaterialBase.query.get(stock_item.base_id) + if base_info: + item_name = base_info.name + item_spec = base_info.spec_model + item_cat = base_info.category + item_type = base_info.material_type except Exception as e: print(f"Error fetching detail for stock_id {d.stock_id}: {e}") @@ -445,7 +449,8 @@ class OutboundService: 'material_type': item_type, 'quantity': qty, 'unit_price': price, - 'subtotal': subtotal + 'subtotal': subtotal, + 'batch_sn': batch_sn }) # 4. 排序输出 diff --git a/inventory-web/src/views/outbound/index.vue b/inventory-web/src/views/outbound/index.vue index 1756a85..5dfab3e 100644 --- a/inventory-web/src/views/outbound/index.vue +++ b/inventory-web/src/views/outbound/index.vue @@ -53,6 +53,7 @@ +