From 69cd23e30ea830a4ea622c5226a786dabe63cced Mon Sep 17 00:00:00 2001 From: yueli Date: Sat, 3 Oct 2026 11:00:38 +0800 Subject: [PATCH] =?UTF-8?q?fix(stocktake):=20=E5=AE=9E=E7=9B=98=200=20?= =?UTF-8?q?=E4=B8=8D=E5=86=8D=E8=A2=AB=E6=98=BE=E7=A4=BA=E6=88=90=201?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit draft/list 与 StocktakeDraft.to_dict 用 float(x or 1) 序列化实盘数,而 0 是 falsy —— 货架盘到 0 的物料会被报成 1。前端「重复扫码」提示读的正是这个值,库管看到“当前实盘为 1”会以为填错而改成 1,真实盘亏就这么被抹掉。改为显式 None 判断,保住合法的 0。 --- inventory-backend/app/api/v1/inbound/stock.py | 6 +++++- inventory-backend/app/models/inbound/stocktake.py | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/inventory-backend/app/api/v1/inbound/stock.py b/inventory-backend/app/api/v1/inbound/stock.py index 4a8a716..4d29c05 100644 --- a/inventory-backend/app/api/v1/inbound/stock.py +++ b/inventory-backend/app/api/v1/inbound/stock.py @@ -811,7 +811,11 @@ def get_drafts(): 'id': row.draft_id, 'user_id': row.user_id, 'uuid': row.uuid, - 'quantity': float(row.quantity or 1), + # ★ 不可写 `or 1`:实盘 0(货架确实空了)是合法且有信息量的值, + # 而 0 是 falsy,`0 or 1` 会把它报成 1 —— 前端「重复扫码」提示读 + # 的就是这个值,库管看到"当前实盘为 1"会以为填错而改成 1, + # 真实的盘亏就这么被抹掉了。 + 'quantity': float(row.quantity) if row.quantity is not None else 0, 'scan_time': row.scan_time.strftime('%Y-%m-%d %H:%M:%S') if row.scan_time else None, 'session_id': row.session_id, 'source_table': row.source_table, diff --git a/inventory-backend/app/models/inbound/stocktake.py b/inventory-backend/app/models/inbound/stocktake.py index a804eea..d0eb18d 100644 --- a/inventory-backend/app/models/inbound/stocktake.py +++ b/inventory-backend/app/models/inbound/stocktake.py @@ -95,7 +95,8 @@ class StocktakeDraft(db.Model): 'id': self.id, 'user_id': self.user_id, 'uuid': self.uuid, - 'quantity': float(self.quantity or 1), + # ★ 同 stock.py 的 /draft/list:0 是合法实盘值,`or 1` 会把它变成 1 + 'quantity': float(self.quantity) if self.quantity is not None else 0, 'scan_time': self.scan_time.strftime('%Y-%m-%d %H:%M:%S') if self.scan_time else None, 'session_id': self.session_id, 'source_table': self.source_table,