From 41a4518911ea9f10acc3ef43972c6544ea7877da Mon Sep 17 00:00:00 2001 From: DXC Date: Wed, 18 Mar 2026 14:37:09 +0800 Subject: [PATCH] fix: map correct database fields for spec and location in excel export --- inventory-backend/app/api/v1/inbound/stock.py | 24 +++++++------------ 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/inventory-backend/app/api/v1/inbound/stock.py b/inventory-backend/app/api/v1/inbound/stock.py index 54f871d..458d79d 100644 --- a/inventory-backend/app/api/v1/inbound/stock.py +++ b/inventory-backend/app/api/v1/inbound/stock.py @@ -567,27 +567,19 @@ def export_stocktake(): # 安全获取 sku stock_sku = getattr(stock, 'sku', None) or getattr(stock, 'SKU', None) or '-' - # 使用 base_id 或 material_id 关联查询物料基础表(安全方式) + # 使用 base_id 关联查询物料基础表 material = None - base_id = getattr(stock, 'base_id', None) or getattr(stock, 'material_id', None) + base_id = getattr(stock, 'base_id', None) if base_id: material = MaterialBase.query.get(base_id) - else: - # 如果没有 base_id,尝试用 code 兜底查询 - if hasattr(MaterialBase, 'code') and stock_sku != '-': - material = MaterialBase.query.filter_by(code=stock_sku).first() - # 规格型号:优先从 material 取,再 fallback 到 stock - spec = ( - getattr(material, 'specification', None) or - getattr(material, 'spec', None) or - getattr(stock, 'spec_model', None) or - getattr(stock, 'standard', None) or - '-' - ) + # 规格型号:从 MaterialBase 的 spec_model 字段获取 + spec = getattr(material, 'spec_model', None) if material else '-' + if not spec or spec == '-': + spec = getattr(stock, 'spec_model', None) or getattr(stock, 'standard', None) or '-' - # 库位:获取真实物理库位 - location = getattr(stock, 'location', None) or getattr(stock, 'position', None) or '-' + # 库位:从库存表的 warehouse_location 字段获取 + location = getattr(stock, 'warehouse_location', None) or '-' return { 'name': material.name if material else stock_sku,