Ship fleet, availability, pricing, dispatch, routing, tracking, and settlement on delivery-service 0.10.8.0 with migrations and phase tests green. Co-authored-by: Cursor <cursoragent@cursor.com>
27 lines
856 B
Python
27 lines
856 B
Python
"""Settlement domain policies — Phase 10.8."""
|
|
from __future__ import annotations
|
|
|
|
from app.models.types import SettlementIntentStatus
|
|
from app.validators.dispatch import validate_dispatch_reason
|
|
from app.validators.settlement import (
|
|
ensure_settlement_transition,
|
|
target_settlement_status,
|
|
)
|
|
|
|
|
|
class SettlementIntentPolicy:
|
|
REQUIRES_REASON = frozenset({"fail", "cancel"})
|
|
|
|
def assert_transition(
|
|
self,
|
|
*,
|
|
action: str,
|
|
current: SettlementIntentStatus,
|
|
reason: str | None = None,
|
|
) -> tuple[SettlementIntentStatus, str | None]:
|
|
ensure_settlement_transition(action=action, current=current)
|
|
cleaned = validate_dispatch_reason(
|
|
reason, required=action in self.REQUIRES_REASON
|
|
)
|
|
return target_settlement_status(action), cleaned
|