TorbatYar/backend/services/delivery/app/policies/settlement.py
Mortezakoohjani 72077908f1 feat(delivery): deploy backend phases 10.2-10.8 through settlement
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>
2026-07-27 21:01:23 +03:30

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