feat(pl): hard-block over-limit contract qty on arrange and remind after success
Validate arranged+this plan qty against fixed contract product quantities on transport arrange; return post-success remaining/framework cumulative reminders. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
d326996976
commit
3011cb9dae
10 files changed
+1424
-8
No files matched your search
@@ -492,6 +492,7 @@ def _build_arrange_result(
|
||||
site_records: list[TransportSiteLinkRead],
|
||||
inventory_records: list[TransportInventoryLinkRead],
|
||||
io_order: Optional[TransportIoOrderBrief] = None,
|
||||
contract_qty_reminder: Optional[dict] = None,
|
||||
) -> TransportArrangeResult:
|
||||
token = transport.driver_access_token or ""
|
||||
result = TransportArrangeResult.model_validate(transport)
|
||||
@@ -500,6 +501,10 @@ def _build_arrange_result(
|
||||
result.site_records = site_records
|
||||
result.inventory_records = inventory_records
|
||||
result.io_order = io_order
|
||||
if contract_qty_reminder:
|
||||
from app.schemas.pl.transport import ContractQtyReminder
|
||||
|
||||
result.contract_qty_reminder = ContractQtyReminder.model_validate(contract_qty_reminder)
|
||||
return result
|
||||
|
||||
|
||||
@@ -784,6 +789,16 @@ def arrange_transport(
|
||||
|
||||
validate_hazard_cert_ready_for_transport(db, tenant_no, plan, products)
|
||||
|
||||
from app.services.pl_contract_plan_qty import (
|
||||
assert_contract_qty_for_arrange,
|
||||
build_contract_qty_reminder_payload,
|
||||
)
|
||||
|
||||
contract_qty_reminders = assert_contract_qty_for_arrange(
|
||||
db, tenant_no=tenant_no, plan_id=plan_id
|
||||
)
|
||||
contract_qty_reminder_payload = build_contract_qty_reminder_payload(contract_qty_reminders)
|
||||
|
||||
# 计算运费
|
||||
freight_amount = payload.freight_amount
|
||||
if payload.freight_type == "by_weight" and payload.freight_price:
|
||||
@@ -884,6 +899,13 @@ def arrange_transport(
|
||||
plan.freight_amount = freight_amount or 0
|
||||
plan.update_by = user.id
|
||||
|
||||
# 安排运输时:关联且仍为「已审批」的合同自动开始执行
|
||||
from app.services.pl_contract_plan_qty import auto_start_execute_approved_contracts
|
||||
|
||||
auto_start_execute_approved_contracts(
|
||||
db, tenant_no=tenant_no, plan=plan, user_id=user.id
|
||||
)
|
||||
|
||||
needs_site_link = plan_requires_site_link(db, tenant_no=tenant_no, plan=plan)
|
||||
|
||||
if is_rearrange:
|
||||
@@ -1030,7 +1052,13 @@ def arrange_transport(
|
||||
|
||||
db.commit()
|
||||
db.refresh(transport)
|
||||
return _build_arrange_result(transport, site_records, inventory_records, io_order_brief)
|
||||
return _build_arrange_result(
|
||||
transport,
|
||||
site_records,
|
||||
inventory_records,
|
||||
io_order_brief,
|
||||
contract_qty_reminder=contract_qty_reminder_payload,
|
||||
)
|
||||
|
||||
|
||||
# =============================================================================
|
||||
|
||||
Reference in new issue
Block a user