fix country code

This commit is contained in:
Раис Юсупалиев
2026-03-09 15:24:10 +03:00
parent 2d68aff34d
commit da301d4bc4
8 changed files with 155 additions and 45 deletions
+12
View File
@@ -18,6 +18,7 @@ class RequestLike(Protocol):
entity: object
from_city: object
to_city: object
country_code: object
weight_kg: object
length_cm: object
width_cm: object
@@ -29,6 +30,7 @@ class NormalizedDeliveryRequest:
entity: str
from_city: str
to_city: str
country_code: str | None
weight_kg: Decimal
length_cm: Decimal
width_cm: Decimal
@@ -58,6 +60,7 @@ def normalize_delivery_request(
entity=str(_get_required_attr(request, "entity")),
from_city=_normalize_text(_get_required_attr(request, "from_city")),
to_city=_normalize_text(_get_required_attr(request, "to_city")),
country_code=_normalize_country_code(_get_optional_attr(request, "country_code")),
weight_kg=_normalize_weight(
_to_decimal(_get_required_attr(request, "weight_kg")),
normalized_weight_scale,
@@ -167,6 +170,15 @@ def _normalize_text(value: object) -> str:
return str(value).strip()
def _normalize_country_code(value: object) -> str | None:
if value is _MISSING or value is None:
return None
normalized = str(value).strip().upper()
if not normalized:
return None
return normalized
def _clamp_scale(scale: int) -> int:
if scale < 0:
return 0