worked_hours to'g'irlandi
This commit is contained in:
@@ -66,9 +66,27 @@ class RetrieveEvaluationrequestSerializer(BaseEvaluationrequestSerializer):
|
||||
|
||||
|
||||
class CreateEvaluationrequestSerializer(serializers.ModelSerializer):
|
||||
location = serializers.DictField(required=False)
|
||||
# Frontend may send locationName
|
||||
locationName = serializers.CharField(write_only=True, required=False)
|
||||
location = serializers.DictField(required=False, allow_empty=True)
|
||||
|
||||
# locationName — string qabul qiladi, location ichida yoki tashqarida yuborsa bo'ladi
|
||||
locationName = serializers.CharField(
|
||||
write_only=True,
|
||||
required=False,
|
||||
allow_null=True,
|
||||
allow_blank=True,
|
||||
)
|
||||
|
||||
# Faqat truck_car uchun majburiy — field darajasida optional qilib belgilaymiz,
|
||||
# validate() da object_type ga qarab tekshiramiz
|
||||
worked_hours = serializers.IntegerField(
|
||||
required=False,
|
||||
allow_null=True,
|
||||
)
|
||||
chassi = serializers.CharField(
|
||||
required=False,
|
||||
allow_null=True,
|
||||
allow_blank=True,
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = EvaluationrequestModel
|
||||
@@ -100,27 +118,25 @@ class CreateEvaluationrequestSerializer(serializers.ModelSerializer):
|
||||
rate_type = attrs.get("rate_type")
|
||||
object_type = attrs.get("object_type")
|
||||
|
||||
# object_type majburiy agar rate_type=auto
|
||||
if rate_type == "auto" and not object_type:
|
||||
raise serializers.ValidationError(
|
||||
{"object_type": "rate_type 'auto' bo'lganda object_type majburiy."}
|
||||
)
|
||||
|
||||
# tex_passport majburiy agar rate_type=auto
|
||||
if rate_type == "auto" and not attrs.get("tex_passport"):
|
||||
raise serializers.ValidationError(
|
||||
{"tex_passport": "rate_type 'auto' bo'lganda tex_passport majburiy."}
|
||||
)
|
||||
|
||||
# worked_hours va chassi faqat yuk automobil uchun majburiy (truck_car)
|
||||
# worked_hours va chassi FAQAT yuk avtomobil (truck_car) uchun majburiy
|
||||
if object_type == "truck_car":
|
||||
if attrs.get("worked_hours") is None:
|
||||
raise serializers.ValidationError(
|
||||
{"worked_hours": "Yuk automobil uchun ishlagan soati majburiy."}
|
||||
{"worked_hours": "Yuk avtomobil uchun ishlagan soati majburiy."}
|
||||
)
|
||||
if attrs.get("chassi") is None:
|
||||
if not attrs.get("chassi"):
|
||||
raise serializers.ValidationError(
|
||||
{"chassi": "Yuk automobil uchun shassi majburiy."}
|
||||
{"chassi": "Yuk avtomobil uchun shassi raqami majburiy."}
|
||||
)
|
||||
|
||||
return attrs
|
||||
@@ -136,7 +152,7 @@ class CreateEvaluationrequestSerializer(serializers.ModelSerializer):
|
||||
location_name = location.get("name") or location.get("locationName")
|
||||
|
||||
if location_name:
|
||||
validated_data["location_name"] = location_name
|
||||
validated_data["location_name"] = str(location_name)
|
||||
|
||||
validated_data["user"] = self.context["request"].user
|
||||
return super().create(validated_data)
|
||||
|
||||
Reference in New Issue
Block a user