diff --git a/inventory-backend/app/api/v1/inbound/stock.py b/inventory-backend/app/api/v1/inbound/stock.py index 7486e9e..6a38b06 100644 --- a/inventory-backend/app/api/v1/inbound/stock.py +++ b/inventory-backend/app/api/v1/inbound/stock.py @@ -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: diff --git a/inventory-web/src/views/stock/stocktake/index.vue b/inventory-web/src/views/stock/stocktake/index.vue index 14a9cfc..8ef1c00 100644 --- a/inventory-web/src/views/stock/stocktake/index.vue +++ b/inventory-web/src/views/stock/stocktake/index.vue @@ -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) {