fix: resolve TypeError between float and Decimal in stocktake excel export

This commit is contained in:
DXC
2026-03-19 11:47:31 +08:00
parent 8db1015f99
commit 7867fc5e40

View File

@ -196,7 +196,7 @@ def add_draft():
# 计算借出未还数量 (quantity - returned_quantity)
borrowed_result = db.session.query(
db.func.sum(TransBorrow.quantity - TransBorrow.returned_quantity)
db.func.sum(db.func.coalesce(TransBorrow.quantity, 0) - db.func.coalesce(TransBorrow.returned_quantity, 0))
).filter(
TransBorrow.source_table == source_table,
TransBorrow.stock_id == stock_id,
@ -756,7 +756,7 @@ def export_stocktake():
TransBorrow.stock_id == stock_id,
TransBorrow.is_returned == False
).all()
total = sum((b.quantity or 0) - (b.returned_quantity or 0) for b in borrowed)
total = sum(float(b.quantity or 0) - float(b.returned_quantity or 0) for b in borrowed)
return total
except:
return 0
@ -842,18 +842,18 @@ def export_stocktake():
ws5.cell(row=row_idx, column=2, value=item['sku']).border = thin_border
ws5.cell(row=row_idx, column=3, value=item['spec']).border = thin_border
ws5.cell(row=row_idx, column=4, value=item['location']).border = thin_border
ws5.cell(row=row_idx, column=5, value=item['stock_qty']).border = thin_border
ws5.cell(row=row_idx, column=6, value=item['actual_qty']).border = thin_border
ws5.cell(row=row_idx, column=7, value=item['diff_qty']).border = thin_border
ws5.cell(row=row_idx, column=5, value=float(item['stock_qty'])).border = thin_border
ws5.cell(row=row_idx, column=6, value=float(item['actual_qty'])).border = thin_border
ws5.cell(row=row_idx, column=7, value=float(item['diff_qty'])).border = thin_border
ws5.cell(row=row_idx, column=8, value=item['status']).border = thin_border
# 同时写入 Sheet 1 (汇总表) - 盘点人和时间留空
ws1.cell(row=master_row_idx, column=1, value=item['name']).border = thin_border
ws1.cell(row=master_row_idx, column=2, value=item['sku']).border = thin_border
ws1.cell(row=master_row_idx, column=3, value=item['spec']).border = thin_border
ws1.cell(row=master_row_idx, column=4, value=item['location']).border = thin_border
ws1.cell(row=master_row_idx, column=5, value=item['stock_qty']).border = thin_border
ws1.cell(row=master_row_idx, column=6, value=item['actual_qty']).border = thin_border
ws1.cell(row=master_row_idx, column=7, value=item['diff_qty']).border = thin_border
ws1.cell(row=master_row_idx, column=5, value=float(item['stock_qty'])).border = thin_border
ws1.cell(row=master_row_idx, column=6, value=float(item['actual_qty'])).border = thin_border
ws1.cell(row=master_row_idx, column=7, value=float(item['diff_qty'])).border = thin_border
ws1.cell(row=master_row_idx, column=8, value="未盘点").border = thin_border
ws1.cell(row=master_row_idx, column=9, value="").border = thin_border
ws1.cell(row=master_row_idx, column=10, value="").border = thin_border