user request yuborishda api fix qilindi #29
@@ -0,0 +1,23 @@
|
|||||||
|
# Generated by Django 5.2.7 on 2026-03-17 13:34
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('evaluation', '0018_evaluationrequestmodel'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='evaluationrequestmodel',
|
||||||
|
name='location_name',
|
||||||
|
field=models.CharField(blank=True, max_length=255, null=True, verbose_name='location name'),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='evaluationrequestmodel',
|
||||||
|
name='chassi',
|
||||||
|
field=models.CharField(blank=True, max_length=100, null=True, verbose_name='chassi'),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -65,8 +65,9 @@ class EvaluationrequestModel(AbstractBaseModel):
|
|||||||
blank=True,
|
blank=True,
|
||||||
null=True,
|
null=True,
|
||||||
)
|
)
|
||||||
chassi = models.IntegerField(
|
chassi = models.CharField(
|
||||||
verbose_name=_("chassi"),
|
verbose_name=_("chassi"),
|
||||||
|
max_length=100,
|
||||||
blank=True,
|
blank=True,
|
||||||
null=True,
|
null=True,
|
||||||
)
|
)
|
||||||
@@ -74,6 +75,12 @@ class EvaluationrequestModel(AbstractBaseModel):
|
|||||||
verbose_name=_("need delivering"),
|
verbose_name=_("need delivering"),
|
||||||
default=True,
|
default=True,
|
||||||
)
|
)
|
||||||
|
location_name = models.CharField(
|
||||||
|
verbose_name=_("location name"),
|
||||||
|
max_length=255,
|
||||||
|
blank=True,
|
||||||
|
null=True,
|
||||||
|
)
|
||||||
location_lat = models.DecimalField(
|
location_lat = models.DecimalField(
|
||||||
verbose_name=_("location latitude"),
|
verbose_name=_("location latitude"),
|
||||||
max_digits=9,
|
max_digits=9,
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ class BaseEvaluationrequestSerializer(serializers.ModelSerializer):
|
|||||||
)
|
)
|
||||||
location = serializers.SerializerMethodField()
|
location = serializers.SerializerMethodField()
|
||||||
|
|
||||||
|
location_name = serializers.CharField(source="location_name", required=False)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = EvaluationrequestModel
|
model = EvaluationrequestModel
|
||||||
fields = [
|
fields = [
|
||||||
@@ -36,6 +38,7 @@ class BaseEvaluationrequestSerializer(serializers.ModelSerializer):
|
|||||||
"chassi",
|
"chassi",
|
||||||
"need_delivering",
|
"need_delivering",
|
||||||
"location",
|
"location",
|
||||||
|
"location_name",
|
||||||
"status",
|
"status",
|
||||||
"status_display",
|
"status_display",
|
||||||
"created_at",
|
"created_at",
|
||||||
@@ -44,7 +47,11 @@ class BaseEvaluationrequestSerializer(serializers.ModelSerializer):
|
|||||||
|
|
||||||
def get_location(self, obj):
|
def get_location(self, obj):
|
||||||
if obj.location_lat is not None and obj.location_lng is not None:
|
if obj.location_lat is not None and obj.location_lng is not None:
|
||||||
return {"lat": float(obj.location_lat), "lng": float(obj.location_lng)}
|
return {
|
||||||
|
"lat": float(obj.location_lat),
|
||||||
|
"lng": float(obj.location_lng),
|
||||||
|
"name": obj.location_name
|
||||||
|
}
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
@@ -59,9 +66,9 @@ class RetrieveEvaluationrequestSerializer(BaseEvaluationrequestSerializer):
|
|||||||
|
|
||||||
|
|
||||||
class CreateEvaluationrequestSerializer(serializers.ModelSerializer):
|
class CreateEvaluationrequestSerializer(serializers.ModelSerializer):
|
||||||
location = serializers.DictField(
|
location = serializers.DictField(required=False)
|
||||||
child=serializers.FloatField(), required=False
|
# Frontend may send locationName
|
||||||
)
|
locationName = serializers.CharField(write_only=True, required=False)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = EvaluationrequestModel
|
model = EvaluationrequestModel
|
||||||
@@ -79,6 +86,7 @@ class CreateEvaluationrequestSerializer(serializers.ModelSerializer):
|
|||||||
"chassi",
|
"chassi",
|
||||||
"need_delivering",
|
"need_delivering",
|
||||||
"location",
|
"location",
|
||||||
|
"locationName",
|
||||||
]
|
]
|
||||||
|
|
||||||
def validate_tex_passport(self, value):
|
def validate_tex_passport(self, value):
|
||||||
@@ -104,7 +112,7 @@ class CreateEvaluationrequestSerializer(serializers.ModelSerializer):
|
|||||||
{"tex_passport": "rate_type 'auto' bo'lganda tex_passport majburiy."}
|
{"tex_passport": "rate_type 'auto' bo'lganda tex_passport majburiy."}
|
||||||
)
|
)
|
||||||
|
|
||||||
# worked_hours va chassi majburiy agar object_type=truck_car
|
# worked_hours va chassi faqat yuk automobil uchun majburiy (truck_car)
|
||||||
if object_type == "truck_car":
|
if object_type == "truck_car":
|
||||||
if attrs.get("worked_hours") is None:
|
if attrs.get("worked_hours") is None:
|
||||||
raise serializers.ValidationError(
|
raise serializers.ValidationError(
|
||||||
@@ -115,18 +123,20 @@ class CreateEvaluationrequestSerializer(serializers.ModelSerializer):
|
|||||||
{"chassi": "Yuk automobil uchun shassi majburiy."}
|
{"chassi": "Yuk automobil uchun shassi majburiy."}
|
||||||
)
|
)
|
||||||
|
|
||||||
# location majburiy agar need_delivering=true
|
|
||||||
if attrs.get("need_delivering", True) and not attrs.get("location"):
|
|
||||||
raise serializers.ValidationError(
|
|
||||||
{"location": "Yetkazish kerak bo'lganda manzil majburiy."}
|
|
||||||
)
|
|
||||||
|
|
||||||
return attrs
|
return attrs
|
||||||
|
|
||||||
def create(self, validated_data):
|
def create(self, validated_data):
|
||||||
location = validated_data.pop("location", None)
|
location = validated_data.pop("location", None)
|
||||||
|
location_name = validated_data.pop("locationName", None)
|
||||||
|
|
||||||
if location:
|
if location:
|
||||||
validated_data["location_lat"] = location.get("lat")
|
validated_data["location_lat"] = location.get("lat")
|
||||||
validated_data["location_lng"] = location.get("lng")
|
validated_data["location_lng"] = location.get("lng")
|
||||||
|
if not location_name:
|
||||||
|
location_name = location.get("name") or location.get("locationName")
|
||||||
|
|
||||||
|
if location_name:
|
||||||
|
validated_data["location_name"] = location_name
|
||||||
|
|
||||||
validated_data["user"] = self.context["request"].user
|
validated_data["user"] = self.context["request"].user
|
||||||
return super().create(validated_data)
|
return super().create(validated_data)
|
||||||
|
|||||||
Reference in New Issue
Block a user