diff --git a/core/apps/evaluation/serializers/history/AutoEvaluationHistory.py b/core/apps/evaluation/serializers/history/AutoEvaluationHistory.py index 593488b..85b0365 100644 --- a/core/apps/evaluation/serializers/history/AutoEvaluationHistory.py +++ b/core/apps/evaluation/serializers/history/AutoEvaluationHistory.py @@ -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): ... diff --git a/core/apps/evaluation/serializers/history/History.py b/core/apps/evaluation/serializers/history/History.py deleted file mode 100644 index db79fe4..0000000 --- a/core/apps/evaluation/serializers/history/History.py +++ /dev/null @@ -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 diff --git a/core/apps/evaluation/serializers/history/QuickEvaluationHistory.py b/core/apps/evaluation/serializers/history/QuickEvaluationHistory.py index 7990dad..9816302 100644 --- a/core/apps/evaluation/serializers/history/QuickEvaluationHistory.py +++ b/core/apps/evaluation/serializers/history/QuickEvaluationHistory.py @@ -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): ... diff --git a/core/apps/evaluation/serializers/history/__init__.py b/core/apps/evaluation/serializers/history/__init__.py index 1506100..5285508 100644 --- a/core/apps/evaluation/serializers/history/__init__.py +++ b/core/apps/evaluation/serializers/history/__init__.py @@ -1,8 +1,2 @@ -from .History import ( # noqa - CreateAutoevaluationhistorySerializer, - CreateQuickevaluationhistorySerializer, - ListAutoevaluationhistorySerializer, - ListQuickevaluationhistorySerializer, - RetrieveAutoevaluationhistorySerializer, - RetrieveQuickevaluationhistorySerializer, -) +from .AutoEvaluationHistory import * # noqa +from .QuickEvaluationHistory import * # noqa diff --git a/core/apps/evaluation/serializers/request/EvaluationRequest.py b/core/apps/evaluation/serializers/request/EvaluationRequest.py index 93d711c..7a4dbe1 100644 --- a/core/apps/evaluation/serializers/request/EvaluationRequest.py +++ b/core/apps/evaluation/serializers/request/EvaluationRequest.py @@ -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)