Merge pull request 'user request yuborishda api fix qilindi' (#29) from fix/user-request into main
Some checks failed
Deploy to Production / build-and-deploy (push) Failing after 1m34s
Some checks failed
Deploy to Production / build-and-deploy (push) Failing after 1m34s
Reviewed-on: #29
This commit is contained in:
@@ -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,
|
||||
null=True,
|
||||
)
|
||||
chassi = models.IntegerField(
|
||||
chassi = models.CharField(
|
||||
verbose_name=_("chassi"),
|
||||
max_length=100,
|
||||
blank=True,
|
||||
null=True,
|
||||
)
|
||||
@@ -74,6 +75,12 @@ class EvaluationrequestModel(AbstractBaseModel):
|
||||
verbose_name=_("need delivering"),
|
||||
default=True,
|
||||
)
|
||||
location_name = models.CharField(
|
||||
verbose_name=_("location name"),
|
||||
max_length=255,
|
||||
blank=True,
|
||||
null=True,
|
||||
)
|
||||
location_lat = models.DecimalField(
|
||||
verbose_name=_("location latitude"),
|
||||
max_digits=9,
|
||||
|
||||
@@ -17,6 +17,8 @@ class BaseEvaluationrequestSerializer(serializers.ModelSerializer):
|
||||
)
|
||||
location = serializers.SerializerMethodField()
|
||||
|
||||
location_name = serializers.CharField(source="location_name", required=False)
|
||||
|
||||
class Meta:
|
||||
model = EvaluationrequestModel
|
||||
fields = [
|
||||
@@ -36,6 +38,7 @@ class BaseEvaluationrequestSerializer(serializers.ModelSerializer):
|
||||
"chassi",
|
||||
"need_delivering",
|
||||
"location",
|
||||
"location_name",
|
||||
"status",
|
||||
"status_display",
|
||||
"created_at",
|
||||
@@ -44,7 +47,11 @@ class BaseEvaluationrequestSerializer(serializers.ModelSerializer):
|
||||
|
||||
def get_location(self, obj):
|
||||
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
|
||||
|
||||
|
||||
@@ -59,9 +66,9 @@ class RetrieveEvaluationrequestSerializer(BaseEvaluationrequestSerializer):
|
||||
|
||||
|
||||
class CreateEvaluationrequestSerializer(serializers.ModelSerializer):
|
||||
location = serializers.DictField(
|
||||
child=serializers.FloatField(), required=False
|
||||
)
|
||||
location = serializers.DictField(required=False)
|
||||
# Frontend may send locationName
|
||||
locationName = serializers.CharField(write_only=True, required=False)
|
||||
|
||||
class Meta:
|
||||
model = EvaluationrequestModel
|
||||
@@ -79,6 +86,7 @@ class CreateEvaluationrequestSerializer(serializers.ModelSerializer):
|
||||
"chassi",
|
||||
"need_delivering",
|
||||
"location",
|
||||
"locationName",
|
||||
]
|
||||
|
||||
def validate_tex_passport(self, value):
|
||||
@@ -104,7 +112,7 @@ class CreateEvaluationrequestSerializer(serializers.ModelSerializer):
|
||||
{"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 attrs.get("worked_hours") is None:
|
||||
raise serializers.ValidationError(
|
||||
@@ -115,18 +123,20 @@ class CreateEvaluationrequestSerializer(serializers.ModelSerializer):
|
||||
{"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
|
||||
|
||||
def create(self, validated_data):
|
||||
location = validated_data.pop("location", None)
|
||||
location_name = validated_data.pop("locationName", None)
|
||||
|
||||
if location:
|
||||
validated_data["location_lat"] = location.get("lat")
|
||||
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
|
||||
return super().create(validated_data)
|
||||
|
||||
Reference in New Issue
Block a user