feat: add empty_weigh and full_weight fields for auto and mechanic rvalution models
This commit is contained in:
@@ -1,33 +0,0 @@
|
||||
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
|
||||
@@ -12,7 +12,7 @@ from weasyprint import HTML
|
||||
from core.apps.evaluation.models import AutoEvaluationModel
|
||||
from core.apps.evaluation.choices.auto import ObjectOwnerType
|
||||
from core.apps.documents.serializers.contract import ContractPDFRequestSerializer
|
||||
from core.apps.documents.services.cbu_rates import fetch_rates
|
||||
from core.services import CurrencyService
|
||||
|
||||
|
||||
UZ_MONTHS = {
|
||||
@@ -301,8 +301,8 @@ class ValuationReportPDFView(APIView):
|
||||
"tech_passport": tech_passport_value,
|
||||
"fuel_type": fuel_type_value,
|
||||
"engine_power": "",
|
||||
"full_weight": "",
|
||||
"empty_weight": "",
|
||||
"full_weight": auto.full_weight if auto.full_weight is not None else "",
|
||||
"empty_weight": auto.empty_weight if auto.empty_weight is not None else "",
|
||||
}
|
||||
|
||||
def _customer_context(self, user):
|
||||
@@ -365,7 +365,7 @@ class ValuationReportPDFView(APIView):
|
||||
}
|
||||
|
||||
def _rates_context(self, target_date):
|
||||
rates = fetch_rates(target_date)
|
||||
rates = CurrencyService.get_rates(target_date)
|
||||
return {
|
||||
"rur": rates.get("RUB", ""),
|
||||
"usd": rates.get("USD", ""),
|
||||
|
||||
Reference in New Issue
Block a user