Files
fastAPI/app/api/v1/box.py
Misaka_Company c370ca36bc feat: add boxing module API — GET /box/info and POST /box
- Add box schemas (BoxInfoResponse, BoxSaveRequest, BoxSaveResponse)
- Add box service with ERP view query and save logic (supports many2one append)
- Add box router with GET /box/info and POST /box endpoints
- Register exception handlers for InvalidZongpaiError, ZongpaiNotFoundError, DuplicateBoxItemError
- Update RequestValidationError handler to cover INVALID_BOX_NO and INVALID_QUANTITY
- Add 7 integration tests for box API

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-05-11 18:04:13 +08:00

24 lines
835 B
Python

from fastapi import APIRouter, Depends, Query
from sqlalchemy.orm import Session
from app.core.database import get_db
from app.schemas.box import BoxInfoResponse, BoxSaveRequest, BoxSaveResponse
from app.services.box_service import get_box_info, save_box_record
router = APIRouter(tags=["boxing"])
@router.get("/box/info", response_model=BoxInfoResponse)
def box_info(
zongpai_no: str = Query(..., description="总排号"),
db: Session = Depends(get_db),
):
"""查询装箱信息:根据总排号查询排产号、数量和已有箱号明细。"""
return get_box_info(db, zongpai_no)
@router.post("/box", response_model=BoxSaveResponse)
def create_box(req: BoxSaveRequest, db: Session = Depends(get_db)):
"""保存装箱记录:将总排号记录到指定箱号中。"""
return save_box_record(db, req)