feat(backend): add draft save helpers for plan follow status drafting
Introduce min-field validation and follow_status resolution for saveMode draft/formal. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
16c657b75e
commit
f28e82c1b3
2 files changed
+89
No files matched your search
@@ -1263,6 +1263,37 @@ def load_plan_contracts_grouped(
|
||||
return {pid: (lists[0], lists[1]) for pid, lists in buckets.items()}
|
||||
|
||||
|
||||
DRAFTABLE_FOLLOW_STATUSES = frozenset({"drafting", "pending_arrange"})
|
||||
|
||||
|
||||
def validate_draft_min_fields(*, belongs_company: Optional[str], create_date) -> None:
|
||||
if not (belongs_company or "").strip():
|
||||
raise HTTPException(status_code=422, detail="请选择归属公司")
|
||||
# create_date 允许为空,由 create/update 用 _resolve_create_date 兜底当天
|
||||
|
||||
|
||||
def resolve_follow_status_on_save(
|
||||
*,
|
||||
save_mode: str,
|
||||
current: Optional[str],
|
||||
is_create: bool,
|
||||
) -> str:
|
||||
mode = (save_mode or "formal").strip() or "formal"
|
||||
if mode == "draft":
|
||||
return "drafting"
|
||||
if is_create:
|
||||
return "pending_arrange"
|
||||
if current == "drafting":
|
||||
return "pending_arrange"
|
||||
return (current or "pending_arrange").strip() or "pending_arrange"
|
||||
|
||||
|
||||
def assert_can_save_as_draft(current_status: Optional[str]) -> None:
|
||||
status = (current_status or "").strip()
|
||||
if status not in DRAFTABLE_FOLLOW_STATUSES:
|
||||
raise HTTPException(status_code=400, detail="当前状态不可暂存")
|
||||
|
||||
|
||||
def validate_create_full(payload: PlanCreateFull) -> None:
|
||||
if not (payload.supplier_id or "").strip() or not (payload.supplier_name or "").strip():
|
||||
raise HTTPException(status_code=422, detail="请选择供方客户")
|
||||
|
||||
Reference in new issue
Block a user