feat: wire contract PDF context and align MechanicAuto with AutoEvaluation
- contract PDF: map report/customer/owner/contract from AutoEvaluationModel fields, accept inspection via POST serializer, fetch CBU.uz currency rates - MechanicAutoEvaluation: add distance_covered, object_owner_residence and car_position/body_type/fuel_type/state_car/assessment_task_type FKs; drop car_type and single tex_passport_file in favour of multi-file FK model Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
0
core/apps/documents/services/__init__.py
Normal file
0
core/apps/documents/services/__init__.py
Normal file
33
core/apps/documents/services/cbu_rates.py
Normal file
33
core/apps/documents/services/cbu_rates.py
Normal file
@@ -0,0 +1,33 @@
|
||||
from datetime import date
|
||||
|
||||
import requests
|
||||
|
||||
CBU_URL = "https://cbu.uz/oz/arkhiv-kursov-valyut/json/{code}/{date}/"
|
||||
TIMEOUT_SECONDS = 5
|
||||
CURRENCY_CODES = ("USD", "EUR", "RUB")
|
||||
|
||||
|
||||
def fetch_rates(target_date):
|
||||
"""CBU.uz dan berilgan sanaga oid USD, EUR, RUB kurslarini olish.
|
||||
|
||||
Tarmoq xatosi yoki notogri javob bolsa bosh dict qaytadi.
|
||||
"""
|
||||
if target_date is None:
|
||||
target_date = date.today()
|
||||
date_str = target_date.strftime("%Y-%m-%d")
|
||||
rates = {}
|
||||
for code in CURRENCY_CODES:
|
||||
try:
|
||||
resp = requests.get(
|
||||
CBU_URL.format(code=code, date=date_str),
|
||||
timeout=TIMEOUT_SECONDS,
|
||||
)
|
||||
resp.raise_for_status()
|
||||
data = resp.json()
|
||||
if isinstance(data, list) and data:
|
||||
rate_value = data[0].get("Rate")
|
||||
if rate_value:
|
||||
rates[code] = rate_value
|
||||
except (requests.RequestException, ValueError):
|
||||
continue
|
||||
return rates
|
||||
Reference in New Issue
Block a user