51 lines
1.3 KiB
Python
51 lines
1.3 KiB
Python
"""运输计划公共页共享纯函数(司机/现场 history 等)。"""
|
|
from __future__ import annotations
|
|
|
|
from datetime import date
|
|
from typing import Optional
|
|
|
|
from app.models.pl_models import PlPlan, PlTransport
|
|
|
|
CRM_PRODUCT_UNIT = "crm_product_unit"
|
|
|
|
|
|
def _resolve_unit_label(unit_map: dict[str, str], unit_code: Optional[str]) -> str:
|
|
code = (unit_code or "").strip()
|
|
if not code:
|
|
return "吨"
|
|
return unit_map.get(code, code)
|
|
|
|
|
|
def _normalize_main_plate(value: Optional[str]) -> str:
|
|
return (value or "").strip()
|
|
|
|
|
|
def _parse_history_date(raw: Optional[str]) -> Optional[date]:
|
|
text = (raw or "").strip()
|
|
if not text:
|
|
return None
|
|
try:
|
|
return date.fromisoformat(text)
|
|
except ValueError:
|
|
return None
|
|
|
|
|
|
def _history_status_label(plan_voided: bool, plan_archived: bool) -> str:
|
|
if plan_voided:
|
|
return "已作废"
|
|
if plan_archived:
|
|
return "已归档"
|
|
return "进行中"
|
|
|
|
|
|
def _resolve_driver_link_flags(
|
|
plan: Optional[PlPlan], transport: PlTransport
|
|
) -> tuple[bool, bool]:
|
|
"""返回 (作废, 归档)。"""
|
|
voided = (
|
|
(plan is not None and plan.follow_status == "cancelled")
|
|
or transport.transport_status == "cancelled"
|
|
)
|
|
archived = bool(plan is not None and plan.archive_status == "archived")
|
|
return voided, archived
|