diff --git a/inventory-backend/app/api/v1/inbound/stock.py b/inventory-backend/app/api/v1/inbound/stock.py index 9b359c9..c230d0a 100644 --- a/inventory-backend/app/api/v1/inbound/stock.py +++ b/inventory-backend/app/api/v1/inbound/stock.py @@ -560,12 +560,17 @@ def export_stocktake(): # 安全获取 sku stock_sku = getattr(stock, 'sku', None) or getattr(stock, 'SKU', None) or '-' - - # 尝试从MaterialBase获取名称 + + # 使用 base_id 或 material_id 关联查询物料基础表(安全方式) material = None - if stock_sku and stock_sku != '-': - material = MaterialBase.query.filter_by(sku=stock_sku).first() - + base_id = getattr(stock, 'base_id', None) or getattr(stock, 'material_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() + return { 'name': material.name if material else stock_sku, 'sku': stock_sku, diff --git a/inventory-web/src/views/stock/stocktake/index.vue b/inventory-web/src/views/stock/stocktake/index.vue index 0ab133d..141fff8 100644 --- a/inventory-web/src/views/stock/stocktake/index.vue +++ b/inventory-web/src/views/stock/stocktake/index.vue @@ -910,7 +910,8 @@ const handleAdjust = async (row: any) => { ElMessage.success(res.message || '调整成功') - // 刷新差异列表 + // 刷新数据并重新打开差异列表 + await loadData() await openVarianceDialog() } catch (e: any) { if (e !== 'cancel') ElMessage.error(e?.message || '操作失败')