fix: resolve sqlalchemy f405 type casting error on stocktake query

This commit is contained in:
DXC
2026-03-13 10:33:17 +08:00
parent d61de5cfc9
commit 13c7357b6f
2 changed files with 19 additions and 16 deletions

View File

@ -127,19 +127,22 @@ def get_drafts():
获取当前用户的盘点进度 获取当前用户的盘点进度
支持过滤: session_id, is_finished, is_processed 支持过滤: session_id, is_finished, is_processed
""" """
user_id = _normalize_user_id(request.args.get('user_id', 'admin')) # user_id 现在由 Token 解析,忽略前端传来的参数以避免类型错误
session_id = request.args.get('session_id') session_id = request.args.get('session_id')
is_finished = request.args.get('is_finished') is_finished_str = request.args.get('is_finished')
is_processed = request.args.get('is_processed') is_processed_str = request.args.get('is_processed')
query = StocktakeDraft.query.filter_by(user_id=user_id) query = StocktakeDraft.query
if session_id: if session_id:
query = query.filter_by(session_id=session_id) query = query.filter_by(session_id=session_id)
if is_finished is not None: # ★ 修复:必须将字符串转换为 Python 布尔值
query = query.filter_by(is_finished=is_finished.lower() in ['true', '1', 'yes']) if is_finished_str is not None:
if is_processed is not None: is_finished_bool = is_finished_str.lower() in ('true', '1', 'yes')
query = query.filter_by(is_processed=is_processed.lower() in ['true', '1', 'yes']) query = query.filter_by(is_finished=is_finished_bool)
if is_processed_str is not None:
is_processed_bool = is_processed_str.lower() in ('true', '1', 'yes')
query = query.filter_by(is_processed=is_processed_bool)
drafts = query.order_by(StocktakeDraft.scan_time.desc()).all() drafts = query.order_by(StocktakeDraft.scan_time.desc()).all()
return jsonify([d.to_dict() for d in drafts]), 200 return jsonify([d.to_dict() for d in drafts]), 200

View File

@ -430,30 +430,30 @@ const api = {
getDrafts: (sessionId?: string) => request({ getDrafts: (sessionId?: string) => request({
url: '/v1/inbound/stock/draft/list', url: '/v1/inbound/stock/draft/list',
method: 'get', method: 'get',
params: { user_id: currentUser, session_id: sessionId } params: { session_id: sessionId }
}), }),
addDraft: (data: any) => request({ addDraft: (data: any) => request({
url: '/v1/inbound/stock/draft/add', url: '/v1/inbound/stock/draft/add',
method: 'post', method: 'post',
data: { ...data, user_id: currentUser, session_id: currentSessionId.value } data: { ...data, session_id: currentSessionId.value }
}), }),
// ★ 新增: 开始新会话 // ★ 新增: 开始新会话
startNewSession: () => request({ startNewSession: () => request({
url: '/v1/inbound/stock/draft/start-new', url: '/v1/inbound/stock/draft/start-new',
method: 'post', method: 'post',
data: { user_id: currentUser } data: {}
}), }),
// ★ 新增: 结束盘点 // ★ 新增: 结束盘点
finishStocktake: () => request({ finishStocktake: () => request({
url: '/v1/inbound/stock/finish', url: '/v1/inbound/stock/finish',
method: 'post', method: 'post',
data: { user_id: currentUser, session_id: currentSessionId.value } data: { session_id: currentSessionId.value }
}), }),
// ★ 新增: 获取差异报告 // ★ 新增: 获取差异报告
getVarianceReport: () => request({ getVarianceReport: () => request({
url: '/v1/inbound/stock/variance-report', url: '/v1/inbound/stock/variance-report',
method: 'get', method: 'get',
params: { user_id: currentUser } params: {}
}), }),
// ★ 新增: 单条库存调整 // ★ 新增: 单条库存调整
adjustStock: (draftId: number, remark: string) => request({ adjustStock: (draftId: number, remark: string) => request({
@ -465,7 +465,7 @@ const api = {
clearDraft: () => request({ clearDraft: () => request({
url: '/v1/inbound/stock/draft/clear', url: '/v1/inbound/stock/draft/clear',
method: 'post', method: 'post',
data: { user_id: currentUser } data: {}
}) })
} }
@ -507,7 +507,7 @@ const checkServerDraft = async () => {
const res: any = await request({ const res: any = await request({
url: '/v1/inbound/stock/draft/list', url: '/v1/inbound/stock/draft/list',
method: 'get', method: 'get',
params: { user_id: currentUser, is_finished: 'false' } params: { is_finished: 'false' }
}) })
serverDraftCount.value = (res && res.length) || 0 serverDraftCount.value = (res && res.length) || 0
} catch (e) {} } catch (e) {}
@ -542,7 +542,7 @@ const resumeSession = async () => {
const drafts: any = await request({ const drafts: any = await request({
url: '/v1/inbound/stock/draft/list', url: '/v1/inbound/stock/draft/list',
method: 'get', method: 'get',
params: { user_id: currentUser, is_finished: 'false' } params: { is_finished: 'false' }
}) })
if (!drafts || drafts.length === 0) { if (!drafts || drafts.length === 0) {