worked_hours to'g'irlandi
This commit is contained in:
@@ -4,11 +4,25 @@ from core.apps.evaluation.models import AutoevaluationhistoryModel
|
|||||||
|
|
||||||
|
|
||||||
class BaseAutoevaluationhistorySerializer(serializers.ModelSerializer):
|
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:
|
class Meta:
|
||||||
model = AutoevaluationhistoryModel
|
model = AutoevaluationhistoryModel
|
||||||
fields = [
|
fields = [
|
||||||
"id",
|
"id",
|
||||||
"name",
|
"event_type",
|
||||||
|
"event_type_display",
|
||||||
|
"actor",
|
||||||
|
"meta",
|
||||||
|
"created_at",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@@ -17,12 +31,9 @@ class ListAutoevaluationhistorySerializer(BaseAutoevaluationhistorySerializer):
|
|||||||
|
|
||||||
|
|
||||||
class RetrieveAutoevaluationhistorySerializer(BaseAutoevaluationhistorySerializer):
|
class RetrieveAutoevaluationhistorySerializer(BaseAutoevaluationhistorySerializer):
|
||||||
class Meta(BaseAutoevaluationhistorySerializer.Meta): ...
|
class Meta(BaseAutoevaluationhistorySerializer.Meta):
|
||||||
|
fields = BaseAutoevaluationhistorySerializer.Meta.fields + ["auto_evaluation"]
|
||||||
|
|
||||||
|
|
||||||
class CreateAutoevaluationhistorySerializer(BaseAutoevaluationhistorySerializer):
|
class CreateAutoevaluationhistorySerializer(BaseAutoevaluationhistorySerializer):
|
||||||
class Meta(BaseAutoevaluationhistorySerializer.Meta):
|
class Meta(BaseAutoevaluationhistorySerializer.Meta): ...
|
||||||
fields = [
|
|
||||||
"id",
|
|
||||||
"name",
|
|
||||||
]
|
|
||||||
|
|||||||
@@ -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
|
|
||||||
@@ -4,11 +4,25 @@ from core.apps.evaluation.models import QuickevaluationhistoryModel
|
|||||||
|
|
||||||
|
|
||||||
class BaseQuickevaluationhistorySerializer(serializers.ModelSerializer):
|
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:
|
class Meta:
|
||||||
model = QuickevaluationhistoryModel
|
model = QuickevaluationhistoryModel
|
||||||
fields = [
|
fields = [
|
||||||
"id",
|
"id",
|
||||||
"name",
|
"event_type",
|
||||||
|
"event_type_display",
|
||||||
|
"actor",
|
||||||
|
"meta",
|
||||||
|
"created_at",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@@ -17,12 +31,9 @@ class ListQuickevaluationhistorySerializer(BaseQuickevaluationhistorySerializer)
|
|||||||
|
|
||||||
|
|
||||||
class RetrieveQuickevaluationhistorySerializer(BaseQuickevaluationhistorySerializer):
|
class RetrieveQuickevaluationhistorySerializer(BaseQuickevaluationhistorySerializer):
|
||||||
class Meta(BaseQuickevaluationhistorySerializer.Meta): ...
|
class Meta(BaseQuickevaluationhistorySerializer.Meta):
|
||||||
|
fields = BaseQuickevaluationhistorySerializer.Meta.fields + ["quick_evaluation"]
|
||||||
|
|
||||||
|
|
||||||
class CreateQuickevaluationhistorySerializer(BaseQuickevaluationhistorySerializer):
|
class CreateQuickevaluationhistorySerializer(BaseQuickevaluationhistorySerializer):
|
||||||
class Meta(BaseQuickevaluationhistorySerializer.Meta):
|
class Meta(BaseQuickevaluationhistorySerializer.Meta): ...
|
||||||
fields = [
|
|
||||||
"id",
|
|
||||||
"name",
|
|
||||||
]
|
|
||||||
|
|||||||
@@ -1,8 +1,2 @@
|
|||||||
from .History import ( # noqa
|
from .AutoEvaluationHistory import * # noqa
|
||||||
CreateAutoevaluationhistorySerializer,
|
from .QuickEvaluationHistory import * # noqa
|
||||||
CreateQuickevaluationhistorySerializer,
|
|
||||||
ListAutoevaluationhistorySerializer,
|
|
||||||
ListQuickevaluationhistorySerializer,
|
|
||||||
RetrieveAutoevaluationhistorySerializer,
|
|
||||||
RetrieveQuickevaluationhistorySerializer,
|
|
||||||
)
|
|
||||||
|
|||||||
@@ -66,9 +66,27 @@ class RetrieveEvaluationrequestSerializer(BaseEvaluationrequestSerializer):
|
|||||||
|
|
||||||
|
|
||||||
class CreateEvaluationrequestSerializer(serializers.ModelSerializer):
|
class CreateEvaluationrequestSerializer(serializers.ModelSerializer):
|
||||||
location = serializers.DictField(required=False)
|
location = serializers.DictField(required=False, allow_empty=True)
|
||||||
# Frontend may send locationName
|
|
||||||
locationName = serializers.CharField(write_only=True, required=False)
|
# 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:
|
class Meta:
|
||||||
model = EvaluationrequestModel
|
model = EvaluationrequestModel
|
||||||
@@ -100,27 +118,25 @@ class CreateEvaluationrequestSerializer(serializers.ModelSerializer):
|
|||||||
rate_type = attrs.get("rate_type")
|
rate_type = attrs.get("rate_type")
|
||||||
object_type = attrs.get("object_type")
|
object_type = attrs.get("object_type")
|
||||||
|
|
||||||
# object_type majburiy agar rate_type=auto
|
|
||||||
if rate_type == "auto" and not object_type:
|
if rate_type == "auto" and not object_type:
|
||||||
raise serializers.ValidationError(
|
raise serializers.ValidationError(
|
||||||
{"object_type": "rate_type 'auto' bo'lganda object_type majburiy."}
|
{"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"):
|
if rate_type == "auto" and not attrs.get("tex_passport"):
|
||||||
raise serializers.ValidationError(
|
raise serializers.ValidationError(
|
||||||
{"tex_passport": "rate_type 'auto' bo'lganda tex_passport majburiy."}
|
{"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 object_type == "truck_car":
|
||||||
if attrs.get("worked_hours") is None:
|
if attrs.get("worked_hours") is None:
|
||||||
raise serializers.ValidationError(
|
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(
|
raise serializers.ValidationError(
|
||||||
{"chassi": "Yuk automobil uchun shassi majburiy."}
|
{"chassi": "Yuk avtomobil uchun shassi raqami majburiy."}
|
||||||
)
|
)
|
||||||
|
|
||||||
return attrs
|
return attrs
|
||||||
@@ -136,7 +152,7 @@ class CreateEvaluationrequestSerializer(serializers.ModelSerializer):
|
|||||||
location_name = location.get("name") or location.get("locationName")
|
location_name = location.get("name") or location.get("locationName")
|
||||||
|
|
||||||
if location_name:
|
if location_name:
|
||||||
validated_data["location_name"] = location_name
|
validated_data["location_name"] = str(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