fix: resolve 500 error in excel export and 404 in stock adjust

This commit is contained in:
DXC
2026-03-18 11:46:38 +08:00
parent b19699cfba
commit 49a66f9be3

View File

@ -526,13 +526,19 @@ def export_stocktake():
if not stock: if not stock:
return {'name': '-', 'sku': '-', 'spec': '-', 'unit': '-'} return {'name': '-', 'sku': '-', 'spec': '-', 'unit': '-'}
# 安全获取 sku
stock_sku = getattr(stock, 'sku', None) or getattr(stock, 'SKU', None) or '-'
# 尝试从MaterialBase获取名称 # 尝试从MaterialBase获取名称
material = MaterialBase.query.filter_by(sku=stock.sku).first() material = None
if stock_sku and stock_sku != '-':
material = MaterialBase.query.filter_by(sku=stock_sku).first()
return { return {
'name': material.name if material else stock.sku, 'name': material.name if material else stock_sku,
'sku': stock.sku, 'sku': stock_sku,
'spec': stock.spec_model or stock.standard or '-', 'spec': getattr(stock, 'spec_model', None) or getattr(stock, 'standard', None) or '-',
'unit': stock.unit or '' 'unit': getattr(stock, 'unit', None) or ''
} }
def set_header_row(ws, headers): def set_header_row(ws, headers):