fix(stocktake): strictly isolate stocktake drafts by session_id in list and finish generation to prevent historical data mixing

This commit is contained in:
DXC
2026-04-03 09:25:52 +08:00
parent 6aec571775
commit 43e1d0aa55
2 changed files with 18 additions and 5 deletions

View File

@ -1131,15 +1131,22 @@ def export_stocktake():
def generate_missing_stocktake():
"""
生成漏盘数据:
找出所有真实库存 > 0但未被盘点扫描到的物料
找出所有真实库存 > 0但未被当前会话盘点扫描到的物料,
自动生成盘点草稿,标记为盘亏(实盘=0差异=-库存数)
"""
try:
# 1. 获取所有已有盘点记录的 (source_table, stock_id) 集合
# 获取 session_id 参数,用于隔离当前会话
data = request.get_json() or {}
session_id = data.get('session_id', '')
if not session_id:
return jsonify({'code': 400, 'msg': '缺少 session_id 参数'}), 400
# 1. 获取当前会话已有盘点记录的 (source_table, stock_id) 集合
existing_records = db.session.query(
StocktakeDraft.source_table,
StocktakeDraft.stock_id
).distinct().all()
).filter(StocktakeDraft.session_id == session_id).distinct().all()
scanned_keys = set()
for src_table, stock_id in existing_records:

View File

@ -986,11 +986,14 @@ const fetchInventoryList = async (silent = false) => {
params: {
page: 1,
limit: 500, // ★ 限制单次加载数量,防止内存溢出
keyword: listKeyword.value
keyword: listKeyword.value,
session_id: currentSessionId.value // ★ 必须传递 session_id 隔离会话
}
})
const scannedDrafts = res?.items || []
// ★ 使用返回的 total 获取真实已盘数量,而不是受限的数组长度
const totalScanned = res?.total || scannedDrafts.length
// 保存全量草稿记录用于全局统计
allScannedDrafts.value = scannedDrafts
@ -1133,7 +1136,10 @@ const handleGenerateMissing = async () => {
btnLoading.value = true
const res = await request({
url: '/v1/inbound/stock/stocktake/generate-missing',
method: 'post'
method: 'post',
data: {
session_id: currentSessionId.value // ★ 必须传递 session_id 隔离会话
}
})
if (res.code === 200) {