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