feat: add empty_weigh and full_weight fields for auto and mechanic rvalution models

This commit is contained in:
xoliqberdiyev
2026-05-06 15:12:46 +05:00
parent a17c2a52ce
commit 23b8c1450f
10 changed files with 123 additions and 79 deletions

View File

@@ -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

View File

@@ -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", ""),

View File

@@ -0,0 +1,31 @@
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("evaluation", "0046_mechanicauto_fields_and_multi_tex_passport"),
]
operations = [
migrations.AddField(
model_name="autoevaluationmodel",
name="full_weight",
field=models.PositiveIntegerField(blank=True, null=True, verbose_name="full weight"),
),
migrations.AddField(
model_name="autoevaluationmodel",
name="empty_weight",
field=models.PositiveIntegerField(blank=True, null=True, verbose_name="empty weight"),
),
migrations.AddField(
model_name="mechanicautoevaluationmodel",
name="full_weight",
field=models.PositiveIntegerField(blank=True, null=True, verbose_name="full weight"),
),
migrations.AddField(
model_name="mechanicautoevaluationmodel",
name="empty_weight",
field=models.PositiveIntegerField(blank=True, null=True, verbose_name="empty weight"),
),
]

View File

@@ -260,6 +260,16 @@ class AutoEvaluationModel(AbstractBaseModel):
blank=True,
null=True,
)
full_weight = models.PositiveIntegerField(
verbose_name=_("full weight"),
blank=True,
null=True,
)
empty_weight = models.PositiveIntegerField(
verbose_name=_("empty weight"),
blank=True,
null=True,
)
# ── Natija ───────────────────────────────────────────────────────
rating_goal = models.CharField(

View File

@@ -256,6 +256,16 @@ class MechanicAutoEvaluationModel(AbstractBaseModel):
blank=True,
null=True,
)
full_weight = models.PositiveIntegerField(
verbose_name=_("full weight"),
blank=True,
null=True,
)
empty_weight = models.PositiveIntegerField(
verbose_name=_("empty weight"),
blank=True,
null=True,
)
# ── Natija ───────────────────────────────────────────────────────
rating_goal = models.CharField(

View File

@@ -73,6 +73,8 @@ class BaseAutoevaluationSerializer(serializers.ModelSerializer):
"car_number",
"manufacture_year",
"car_color",
"full_weight",
"empty_weight",
"distance_covered",
"car_position",
"body_type",
@@ -214,6 +216,8 @@ class UpdateAutoevaluationSerializer(serializers.ModelSerializer):
"manufacture_year",
"car_dvigatel_number",
"car_color",
"full_weight",
"empty_weight",
"distance_covered",
"car_position",
"body_type",
@@ -361,6 +365,8 @@ class CreateAutoevaluationSerializer(serializers.ModelSerializer):
"manufacture_year",
"car_dvigatel_number",
"car_color",
"full_weight",
"empty_weight",
"distance_covered",
"car_position",
"body_type",
@@ -493,6 +499,8 @@ class AutoEvaluationModelSerializer(serializers.ModelSerializer):
"manufacture_year",
"car_dvigatel_number",
"car_color",
"full_weight",
"empty_weight",
"distance_covered",
"car_position",
"body_type",

View File

@@ -73,6 +73,8 @@ class BaseMechanicAutoevaluationSerializer(serializers.ModelSerializer):
"car_number",
"manufacture_year",
"car_color",
"full_weight",
"empty_weight",
"distance_covered",
"car_position",
"body_type",
@@ -213,6 +215,8 @@ class UpdateMechanicAutoevaluationSerializer(serializers.ModelSerializer):
"manufacture_year",
"car_dvigatel_number",
"car_color",
"full_weight",
"empty_weight",
"distance_covered",
"car_position",
"body_type",
@@ -363,6 +367,8 @@ class CreateMechanicAutoevaluationSerializer(serializers.ModelSerializer):
"manufacture_year",
"car_dvigatel_number",
"car_color",
"full_weight",
"empty_weight",
"distance_covered",
"car_position",
"body_type",
@@ -480,6 +486,8 @@ class MechanicAutoEvaluationModelSerializer(serializers.ModelSerializer):
"manufacture_year",
"car_dvigatel_number",
"car_color",
"full_weight",
"empty_weight",
"distance_covered",
"car_position",
"body_type",