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

@ -522,17 +522,23 @@ def export_stocktake():
stock = StockProduct.query.get(stock_id) if StockProduct else None
else:
return {'name': '-', 'sku': '-', 'spec': '-', 'unit': '-'}
if not stock:
return {'name': '-', 'sku': '-', 'spec': '-', 'unit': '-'}
# 安全获取 sku
stock_sku = getattr(stock, 'sku', None) or getattr(stock, 'SKU', None) or '-'
# 尝试从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 {
'name': material.name if material else stock.sku,
'sku': stock.sku,
'spec': stock.spec_model or stock.standard or '-',
'unit': stock.unit or ''
'name': material.name if material else stock_sku,
'sku': stock_sku,
'spec': getattr(stock, 'spec_model', None) or getattr(stock, 'standard', None) or '-',
'unit': getattr(stock, 'unit', None) or ''
}
def set_header_row(ws, headers):