feat: add one-to-one box mode with duplicate bind check
Add box_mode field to BoxSaveRequest and DuplicateZongpaiBindError exception. In one-to-one mode, prevent the same zongpai from being packed into multiple boxes, returning 409 with existing box info. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -23,6 +23,13 @@ class DuplicateBoxItemError(Exception):
|
||||
self.box_no = box_no
|
||||
|
||||
|
||||
class DuplicateZongpaiBindError(Exception):
|
||||
def __init__(self, paichan_no: str, box_no: int, zongpai_no: str):
|
||||
self.paichan_no = paichan_no
|
||||
self.box_no = box_no
|
||||
self.zongpai_no = zongpai_no
|
||||
|
||||
|
||||
def query_erp_info(db: Session, zongpai_no: str) -> dict:
|
||||
"""从 ERP 视图查询总排号对应的排产号和数量。"""
|
||||
sql = text(_erp_info_sql(db))
|
||||
@@ -101,6 +108,19 @@ def save_box_record(db: Session, req: BoxSaveRequest) -> dict:
|
||||
erp = query_erp_info(db, req.zongpai_no)
|
||||
paichan_no = erp["paichan_no"]
|
||||
|
||||
if req.box_mode == "one-to-one":
|
||||
existing_box_no = (
|
||||
db.query(FinishedGoodsBox.box_no)
|
||||
.join(FinishedGoodsBoxItem, FinishedGoodsBox.id == FinishedGoodsBoxItem.box_id)
|
||||
.filter(
|
||||
FinishedGoodsBox.paichan_no == paichan_no,
|
||||
FinishedGoodsBoxItem.zongpai_no == req.zongpai_no,
|
||||
)
|
||||
.scalar()
|
||||
)
|
||||
if existing_box_no is not None:
|
||||
raise DuplicateZongpaiBindError(paichan_no, existing_box_no, req.zongpai_no)
|
||||
|
||||
box = (
|
||||
db.query(FinishedGoodsBox)
|
||||
.filter(
|
||||
|
||||
Reference in New Issue
Block a user