From 893e7250dbaee4ba187285c1fdcbe96383fe8ab8 Mon Sep 17 00:00:00 2001 From: yueli Date: Mon, 31 Aug 2026 16:00:20 +0800 Subject: [PATCH] =?UTF-8?q?fix(api):=20update-stocktake-quantity=20?= =?UTF-8?q?=E6=8C=89=20session=5Fid=20=E9=9A=94=E7=A6=BB=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=EF=BC=8C=E9=98=B2=E6=AD=A2=E8=B7=A8=E4=BC=9A=E8=AF=9D=E8=AF=AF?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 后端 update_stocktake_quantity 原只按 stock_id+source_table 查草稿, 不同盘点会话会相互覆盖实盘数。后端增加 session_id 过滤, 前端 handleQuantityChange 配套传入当前会话ID,API 类型同步补全。 --- inventory-backend/app/api/v1/inbound/stock.py | 14 +++++++++----- inventory-web/src/api/inbound/stock.ts | 2 +- inventory-web/src/views/stock/stocktake/index.vue | 3 ++- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/inventory-backend/app/api/v1/inbound/stock.py b/inventory-backend/app/api/v1/inbound/stock.py index 68da294..52c69f2 100644 --- a/inventory-backend/app/api/v1/inbound/stock.py +++ b/inventory-backend/app/api/v1/inbound/stock.py @@ -1741,16 +1741,20 @@ def update_stocktake_quantity(): data = request.json stock_id = data.get('stock_id') source_table = data.get('source_table') + session_id = data.get('session_id') # ★ 修复:按会话隔离,防止跨会话误改 quantity = float(data.get('quantity', 0)) - + if not stock_id or not source_table: return jsonify({'code': 400, 'msg': '缺少必要参数'}), 400 - - # 查找对应的盘点记录 - draft = StocktakeDraft.query.filter_by( + + # 查找对应的盘点记录(★ 修复:限定 session_id,避免不同盘点会话相互覆盖) + query = StocktakeDraft.query.filter_by( stock_id=stock_id, source_table=source_table - ).first() + ) + if session_id: + query = query.filter_by(session_id=session_id) + draft = query.first() if not draft: return jsonify({'code': 404, 'msg': '未找到盘点记录'}), 404 diff --git a/inventory-web/src/api/inbound/stock.ts b/inventory-web/src/api/inbound/stock.ts index 798bbbd..de5370f 100644 --- a/inventory-web/src/api/inbound/stock.ts +++ b/inventory-web/src/api/inbound/stock.ts @@ -107,7 +107,7 @@ export function getAllStocktakeItems(params?: { keyword?: string; session_id?: s } // 更新盘点实盘数(手动修改) -export function updateStocktakeQuantity(data: { stock_id: number; source_table: string; quantity: number }) { +export function updateStocktakeQuantity(data: { stock_id: number; source_table: string; quantity: number; session_id?: string }) { return request({ url: '/v1/inbound/stock/stocktake/update-quantity', method: 'post', diff --git a/inventory-web/src/views/stock/stocktake/index.vue b/inventory-web/src/views/stock/stocktake/index.vue index d3705fb..c0ba2cb 100644 --- a/inventory-web/src/views/stock/stocktake/index.vue +++ b/inventory-web/src/views/stock/stocktake/index.vue @@ -1102,7 +1102,8 @@ const handleQuantityChange = async (row: any, val: number) => { await updateStocktakeQuantity({ stock_id: row.stock_id, source_table: row.source_table, - quantity: val + quantity: val, + session_id: currentSessionId.value // ★ 传入会话ID,后端按会话隔离更新 }) ElMessage.success('实盘数已更新') } catch (e) {