fix: resolve 500 error in excel export and 404 in stock adjust
This commit is contained in:
@ -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):
|
||||
|
||||
Reference in New Issue
Block a user