feat(pl): site io-order feedback accepts and stores brand qtys
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
b0346e688d
commit
006ed6586c
4 files changed
+303
-11
No files matched your search
@@ -22,6 +22,7 @@ from app.schemas.pl.io_order import IoOrderListResponse, IoOrderPatch, IoOrderRe
|
||||
from app.services.pl_io_order_service import (
|
||||
dump_feedback_images,
|
||||
order_header_to_dict,
|
||||
update_io_order_items_qty_and_brand,
|
||||
)
|
||||
|
||||
inbound_router = APIRouter(prefix="/inbound", tags=["运输计划-入库单"])
|
||||
@@ -138,13 +139,34 @@ def _patch_order(
|
||||
header.remark = payload.remark
|
||||
if payload.items:
|
||||
by_id = {it.id: it for it in items}
|
||||
qty_map: dict[str, Decimal] = {}
|
||||
brand_qty_map: dict[str, list[dict]] | None = None
|
||||
for patch in payload.items:
|
||||
row = by_id.get(patch.id)
|
||||
if not row:
|
||||
continue
|
||||
row.actual_qty = Decimal(str(patch.actual_qty))
|
||||
row.qty_source = "manual"
|
||||
row.update_by = user.id
|
||||
qty_map[patch.id] = Decimal(str(patch.actual_qty))
|
||||
if patch.brand_qtys is not None:
|
||||
if brand_qty_map is None:
|
||||
brand_qty_map = {}
|
||||
brand_qty_map[patch.id] = [
|
||||
b.model_dump(by_alias=True) for b in patch.brand_qtys
|
||||
]
|
||||
effective_status = payload.status if payload.status is not None else header.status
|
||||
try:
|
||||
update_io_order_items_qty_and_brand(
|
||||
db,
|
||||
kind=kind,
|
||||
tenant_no=tenant_no,
|
||||
order_id=header.id,
|
||||
items=items,
|
||||
item_qty=qty_map,
|
||||
item_brand_qtys=brand_qty_map,
|
||||
enforce_brand=(effective_status == "completed"),
|
||||
user_id=user.id,
|
||||
)
|
||||
except ValueError as exc:
|
||||
raise HTTPException(status_code=400, detail=str(exc)) from exc
|
||||
header.update_by = user.id
|
||||
db.commit()
|
||||
header, items = _get_order(db, tenant_no, kind, order_id)
|
||||
|
||||
@@ -82,18 +82,29 @@ def _make_handlers(kind: str):
|
||||
if page["voided"]:
|
||||
return error_response(400, "单据已作废,无法提交")
|
||||
qty_map = {x.id: Decimal(str(x.actual_qty)) for x in payload.items}
|
||||
brand_qty_map: dict[str, list[dict]] | None = None
|
||||
if any(x.brand_qtys is not None for x in payload.items):
|
||||
brand_qty_map = {}
|
||||
for x in payload.items:
|
||||
if x.brand_qtys is not None:
|
||||
brand_qty_map[x.id] = [
|
||||
b.model_dump(by_alias=True) for b in x.brand_qtys
|
||||
]
|
||||
images = payload.images
|
||||
if not images:
|
||||
images = parse_feedback_images(header.site_feedback_images)
|
||||
try:
|
||||
apply_site_feedback(
|
||||
db,
|
||||
kind=kind,
|
||||
header=header,
|
||||
items=items,
|
||||
item_qty=qty_map,
|
||||
remark=payload.remark,
|
||||
images=images,
|
||||
status=payload.status,
|
||||
item_brand_qtys=brand_qty_map,
|
||||
enforce_brand=(payload.status == "completed"),
|
||||
)
|
||||
except ValueError as exc:
|
||||
return error_response(400, str(exc))
|
||||
|
||||
Reference in new issue
Block a user