diff --git a/inventory-backend/app/services/borrow_service.py b/inventory-backend/app/services/borrow_service.py index 3dbc33e..1d94240 100644 --- a/inventory-backend/app/services/borrow_service.py +++ b/inventory-backend/app/services/borrow_service.py @@ -64,7 +64,16 @@ class BorrowApprovalService: def submit_approval(applicant_id, items, allowed_approvers, remark=None, approver_id=None, borrower_name=None, force_approval=False): """ - 提交借库申请(仅存储意向,不扣库存) + 提交借库申请。 + + ★ 库存语义:**提交即预占**(Phase 1 起)。 + 本函数会调用 reserve_for_items() 锁定具体批次并扣减 available_quantity, + 不动 stock_quantity —— 借出期间该批货不可再被他人领用。 + 预占的释放时机: + · 驳回 / 撤回 → release_reserved() 全额归还; + · 扫码执行 → restore_then_deduct() 先全量释放、再按实扫批次扣减。 + (原注释写「仅存储意向,不扣库存」,是 Phase 1 改造前的旧描述, + 与下方实现不符,已修正。) Args: applicant_id: 申请人ID diff --git a/inventory-backend/app/services/scrap_sources.py b/inventory-backend/app/services/scrap_sources.py index c9abcc1..76151df 100644 --- a/inventory-backend/app/services/scrap_sources.py +++ b/inventory-backend/app/services/scrap_sources.py @@ -29,7 +29,7 @@ """ import logging -from app.extensions import db +from app.extensions import db, beijing_time logger = logging.getLogger(__name__) @@ -368,7 +368,6 @@ class BorrowScrapAdapter(ScrapSourceAdapter): (base.spec_model if base else '') or '') def deduct(self, row_id, qty, req, operator_name): - from datetime import datetime from app.models.transaction import TransScrap, TransBorrow record = TransBorrow.query.with_for_update().get(row_id) @@ -390,7 +389,10 @@ class BorrowScrapAdapter(ScrapSourceAdapter): # 1) 标记借用记录:不再追讨归还 record.is_returned = True record.status = 'scrapped' - record.return_time = datetime.now() + # ★ 时间口径:与 borrow_time / 归还流水统一取北京时间。 + # 原用 datetime.now()(容器 UTC),会让报废时间在台账上比实际早 8 小时, + # 与同一行的 borrow_time 自相矛盾,也让流转时间线出现倒序假象。 + record.return_time = beijing_time() record.return_operator = operator_name # 2) 扣总库存(该物品确认损失);可用量已在借出时冻结,不重复扣