fix: resolve sqlalchemy f405 type casting error on stocktake query
This commit is contained in:
@ -127,19 +127,22 @@ def get_drafts():
|
||||
获取当前用户的盘点进度
|
||||
支持过滤: 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')
|
||||
is_finished = request.args.get('is_finished')
|
||||
is_processed = request.args.get('is_processed')
|
||||
is_finished_str = request.args.get('is_finished')
|
||||
is_processed_str = request.args.get('is_processed')
|
||||
|
||||
query = StocktakeDraft.query.filter_by(user_id=user_id)
|
||||
query = StocktakeDraft.query
|
||||
|
||||
if session_id:
|
||||
query = query.filter_by(session_id=session_id)
|
||||
if is_finished is not None:
|
||||
query = query.filter_by(is_finished=is_finished.lower() in ['true', '1', 'yes'])
|
||||
if is_processed is not None:
|
||||
query = query.filter_by(is_processed=is_processed.lower() in ['true', '1', 'yes'])
|
||||
# ★ 修复:必须将字符串转换为 Python 布尔值
|
||||
if is_finished_str is not None:
|
||||
is_finished_bool = is_finished_str.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()
|
||||
return jsonify([d.to_dict() for d in drafts]), 200
|
||||
|
||||
@ -430,30 +430,30 @@ const api = {
|
||||
getDrafts: (sessionId?: string) => request({
|
||||
url: '/v1/inbound/stock/draft/list',
|
||||
method: 'get',
|
||||
params: { user_id: currentUser, session_id: sessionId }
|
||||
params: { session_id: sessionId }
|
||||
}),
|
||||
addDraft: (data: any) => request({
|
||||
url: '/v1/inbound/stock/draft/add',
|
||||
method: 'post',
|
||||
data: { ...data, user_id: currentUser, session_id: currentSessionId.value }
|
||||
data: { ...data, session_id: currentSessionId.value }
|
||||
}),
|
||||
// ★ 新增: 开始新会话
|
||||
startNewSession: () => request({
|
||||
url: '/v1/inbound/stock/draft/start-new',
|
||||
method: 'post',
|
||||
data: { user_id: currentUser }
|
||||
data: {}
|
||||
}),
|
||||
// ★ 新增: 结束盘点
|
||||
finishStocktake: () => request({
|
||||
url: '/v1/inbound/stock/finish',
|
||||
method: 'post',
|
||||
data: { user_id: currentUser, session_id: currentSessionId.value }
|
||||
data: { session_id: currentSessionId.value }
|
||||
}),
|
||||
// ★ 新增: 获取差异报告
|
||||
getVarianceReport: () => request({
|
||||
url: '/v1/inbound/stock/variance-report',
|
||||
method: 'get',
|
||||
params: { user_id: currentUser }
|
||||
params: {}
|
||||
}),
|
||||
// ★ 新增: 单条库存调整
|
||||
adjustStock: (draftId: number, remark: string) => request({
|
||||
@ -465,7 +465,7 @@ const api = {
|
||||
clearDraft: () => request({
|
||||
url: '/v1/inbound/stock/draft/clear',
|
||||
method: 'post',
|
||||
data: { user_id: currentUser }
|
||||
data: {}
|
||||
})
|
||||
}
|
||||
|
||||
@ -507,7 +507,7 @@ const checkServerDraft = async () => {
|
||||
const res: any = await request({
|
||||
url: '/v1/inbound/stock/draft/list',
|
||||
method: 'get',
|
||||
params: { user_id: currentUser, is_finished: 'false' }
|
||||
params: { is_finished: 'false' }
|
||||
})
|
||||
serverDraftCount.value = (res && res.length) || 0
|
||||
} catch (e) {}
|
||||
@ -542,7 +542,7 @@ const resumeSession = async () => {
|
||||
const drafts: any = await request({
|
||||
url: '/v1/inbound/stock/draft/list',
|
||||
method: 'get',
|
||||
params: { user_id: currentUser, is_finished: 'false' }
|
||||
params: { is_finished: 'false' }
|
||||
})
|
||||
|
||||
if (!drafts || drafts.length === 0) {
|
||||
|
||||
Reference in New Issue
Block a user