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>
30 lines
860 B
Python
30 lines
860 B
Python
"""Shared service helpers for delivery phases 10.2+."""
|
|
from __future__ import annotations
|
|
|
|
from datetime import date, datetime
|
|
from decimal import Decimal
|
|
from typing import Any
|
|
from uuid import UUID
|
|
|
|
from shared.security import CurrentUser
|
|
|
|
|
|
def actor_id(actor: CurrentUser | None) -> str | None:
|
|
return actor.user_id if actor else None
|
|
|
|
|
|
def jsonable(data: dict[str, Any]) -> dict[str, Any]:
|
|
out: dict[str, Any] = {}
|
|
for key, value in data.items():
|
|
if isinstance(value, UUID):
|
|
out[key] = str(value)
|
|
elif isinstance(value, Decimal):
|
|
out[key] = str(value)
|
|
elif isinstance(value, (datetime, date)):
|
|
out[key] = value.isoformat()
|
|
elif hasattr(value, "value"):
|
|
out[key] = value.value
|
|
else:
|
|
out[key] = value
|
|
return out
|