worked_hours to'g'irlandi #37

Merged
husanjon merged 1 commits from fix/evaluation-request into main 2026-04-02 12:18:24 +00:00
5 changed files with 64 additions and 94 deletions

View File

@@ -4,11 +4,25 @@ from core.apps.evaluation.models import AutoevaluationhistoryModel
class BaseAutoevaluationhistorySerializer(serializers.ModelSerializer):
event_type_display = serializers.CharField(source="get_event_type_display", read_only=True)
actor = serializers.SerializerMethodField()
def get_actor(self, obj):
return {
"id": obj.actor_id,
"full_name": obj.actor_full_name,
"role": obj.actor_role,
}
class Meta:
model = AutoevaluationhistoryModel
fields = [
"id",
"name",
"event_type",
"event_type_display",
"actor",
"meta",
"created_at",
]
@@ -17,12 +31,9 @@ class ListAutoevaluationhistorySerializer(BaseAutoevaluationhistorySerializer):
class RetrieveAutoevaluationhistorySerializer(BaseAutoevaluationhistorySerializer):
class Meta(BaseAutoevaluationhistorySerializer.Meta): ...
class Meta(BaseAutoevaluationhistorySerializer.Meta):
fields = BaseAutoevaluationhistorySerializer.Meta.fields + ["auto_evaluation"]
class CreateAutoevaluationhistorySerializer(BaseAutoevaluationhistorySerializer):
class Meta(BaseAutoevaluationhistorySerializer.Meta):
fields = [
"id",
"name",
]
class Meta(BaseAutoevaluationhistorySerializer.Meta): ...

View File

@@ -1,62 +0,0 @@
from rest_framework import serializers
from core.apps.evaluation.models import AutoevaluationhistoryModel, QuickevaluationhistoryModel
class BaseHistorySerializer(serializers.ModelSerializer):
event_type_display = serializers.CharField(source="get_event_type_display", read_only=True)
actor = serializers.SerializerMethodField()
def get_actor(self, obj):
return {
"id": obj.actor_id,
"full_name": obj.actor_full_name,
"role": obj.actor_role,
}
# ─── AutoEvaluation History ────────────────────────────────────────────────
class ListAutoevaluationhistorySerializer(BaseHistorySerializer):
class Meta:
model = AutoevaluationhistoryModel
fields = [
"id",
"event_type",
"event_type_display",
"actor",
"meta",
"created_at",
]
class RetrieveAutoevaluationhistorySerializer(ListAutoevaluationhistorySerializer):
class Meta(ListAutoevaluationhistorySerializer.Meta):
fields = ListAutoevaluationhistorySerializer.Meta.fields + ["auto_evaluation"]
# Read-only — API orqali yozilmaydi, faqat signallar yozadi
CreateAutoevaluationhistorySerializer = ListAutoevaluationhistorySerializer
# ─── QuickEvaluation History ───────────────────────────────────────────────
class ListQuickevaluationhistorySerializer(BaseHistorySerializer):
class Meta:
model = QuickevaluationhistoryModel
fields = [
"id",
"event_type",
"event_type_display",
"actor",
"meta",
"created_at",
]
class RetrieveQuickevaluationhistorySerializer(ListQuickevaluationhistorySerializer):
class Meta(ListQuickevaluationhistorySerializer.Meta):
fields = ListQuickevaluationhistorySerializer.Meta.fields + ["quick_evaluation"]
CreateQuickevaluationhistorySerializer = ListQuickevaluationhistorySerializer

View File

@@ -4,11 +4,25 @@ from core.apps.evaluation.models import QuickevaluationhistoryModel
class BaseQuickevaluationhistorySerializer(serializers.ModelSerializer):
event_type_display = serializers.CharField(source="get_event_type_display", read_only=True)
actor = serializers.SerializerMethodField()
def get_actor(self, obj):
return {
"id": obj.actor_id,
"full_name": obj.actor_full_name,
"role": obj.actor_role,
}
class Meta:
model = QuickevaluationhistoryModel
fields = [
"id",
"name",
"event_type",
"event_type_display",
"actor",
"meta",
"created_at",
]
@@ -17,12 +31,9 @@ class ListQuickevaluationhistorySerializer(BaseQuickevaluationhistorySerializer)
class RetrieveQuickevaluationhistorySerializer(BaseQuickevaluationhistorySerializer):
class Meta(BaseQuickevaluationhistorySerializer.Meta): ...
class Meta(BaseQuickevaluationhistorySerializer.Meta):
fields = BaseQuickevaluationhistorySerializer.Meta.fields + ["quick_evaluation"]
class CreateQuickevaluationhistorySerializer(BaseQuickevaluationhistorySerializer):
class Meta(BaseQuickevaluationhistorySerializer.Meta):
fields = [
"id",
"name",
]
class Meta(BaseQuickevaluationhistorySerializer.Meta): ...

View File

@@ -1,8 +1,2 @@
from .History import ( # noqa
CreateAutoevaluationhistorySerializer,
CreateQuickevaluationhistorySerializer,
ListAutoevaluationhistorySerializer,
ListQuickevaluationhistorySerializer,
RetrieveAutoevaluationhistorySerializer,
RetrieveQuickevaluationhistorySerializer,
)
from .AutoEvaluationHistory import * # noqa
from .QuickEvaluationHistory import * # noqa

View File

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