diff --git a/config/conf/navigation.py b/config/conf/navigation.py index c4731b4..2cac38d 100644 --- a/config/conf/navigation.py +++ b/config/conf/navigation.py @@ -150,4 +150,20 @@ PAGES = [ }, ], }, + { + "title": _("Auto baholash"), + "separator": True, + "items": [ + { + "title": _("Hujjatlar"), + "icon": "attach_file", + "link": reverse_lazy("admin:evaluation_documentmodel_changelist"), + }, + { + "title": _("Kategoriyalar"), + "icon": "category", + "link": reverse_lazy("admin:evaluation_documentcategorymodel_changelist"), + } + ] + } ] diff --git a/core/apps/chat/migrations/0003_alter_chatmessagemodel_options_and_more.py b/core/apps/chat/migrations/0003_alter_chatmessagemodel_options_and_more.py new file mode 100644 index 0000000..6692738 --- /dev/null +++ b/core/apps/chat/migrations/0003_alter_chatmessagemodel_options_and_more.py @@ -0,0 +1,22 @@ +# Generated by Django 5.2.7 on 2026-04-03 10:58 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('chat', '0002_chatroom_and_message_media'), + ] + + operations = [ + migrations.AlterModelOptions( + name='chatmessagemodel', + options={'ordering': ['created_at'], 'verbose_name': 'Chat Xabar', 'verbose_name_plural': 'Chat Xabarlar'}, + ), + migrations.AlterField( + model_name='chatroommodel', + name='type', + field=models.CharField(choices=[('auto_evaluation', 'AutoEvaluation xonasi'), ('direct', "To'g'ridan-to'g'ri")], db_index=True, default='auto_evaluation', max_length=20, verbose_name='type'), + ), + ] diff --git a/core/apps/evaluation/admin/__init__.py b/core/apps/evaluation/admin/__init__.py index bc24d35..a625148 100644 --- a/core/apps/evaluation/admin/__init__.py +++ b/core/apps/evaluation/admin/__init__.py @@ -1,6 +1,7 @@ from .auto import * # noqa from .customer import * # noqa from .document import * # noqa +from .documentcategory import * # noqa from .history import * # noqa from .movable import * # noqa from .quick import * # noqa diff --git a/core/apps/evaluation/admin/document.py b/core/apps/evaluation/admin/document.py index 795e24d..b709441 100644 --- a/core/apps/evaluation/admin/document.py +++ b/core/apps/evaluation/admin/document.py @@ -1,7 +1,7 @@ from django.contrib import admin from unfold.admin import ModelAdmin -from core.apps.evaluation.models import ValuationDocumentModel +from core.apps.evaluation.models import DocumentModel, ValuationDocumentModel @admin.register(ValuationDocumentModel) @@ -23,20 +23,37 @@ class ValuationDocumentAdmin(ModelAdmin): readonly_fields = ("created_at", "updated_at") autocomplete_fields = ("valuation", "uploaded_by") fieldsets = ( - ("Hujjat", { - "fields": ( - "valuation", - "document_type", - "title", - "file", - "uploaded_by", - ), - }), - ("Qo'shimcha", { - "fields": ("description",), - }), - ("Tizim", { - "classes": ("collapse",), - "fields": ("created_at", "updated_at"), - }), + ( + "Hujjat", + { + "fields": ( + "valuation", + "document_type", + "title", + "file", + "uploaded_by", + ), + }, + ), + ( + "Qo'shimcha", + { + "fields": ("description",), + }, + ), + ( + "Tizim", + { + "classes": ("collapse",), + "fields": ("created_at", "updated_at"), + }, + ), + ) + + +@admin.register(DocumentModel) +class DocumentAdmin(ModelAdmin): + list_display = ( + "id", + "__str__", ) diff --git a/core/apps/evaluation/admin/documentcategory.py b/core/apps/evaluation/admin/documentcategory.py new file mode 100644 index 0000000..c459d78 --- /dev/null +++ b/core/apps/evaluation/admin/documentcategory.py @@ -0,0 +1,57 @@ +from django.contrib import admin +from unfold.admin import ModelAdmin + +from core.apps.evaluation.models import DocumentcategoryModel + + +@admin.register(DocumentcategoryModel) +class DocumentcategoryAdmin(ModelAdmin): + list_display = ( + "id", + "label", + "value", + "created_at", + "updated_at" + ) + search_fields = ( + "label", + "value", + ) + list_filter = ( + "created_at", + "updated_at", + ) + readonly_fields = ( + "created_at", + "updated_at", + ) + fieldsets = ( + ( + ("Uzbekcha"), + { + "fields": ( + "label_uz", + "value_uz", + ) + } + ), + ( + ("Ruscha"), + { + "fields": ( + "label_ru", + "value_ru", + ) + } + ), + ( + ("Inglizcha"), + { + "fields": ( + "label_en", + "value_en", + ) + } + ), + ) + list_display_links =list_display diff --git a/core/apps/evaluation/filters/__init__.py b/core/apps/evaluation/filters/__init__.py index bc24d35..a625148 100644 --- a/core/apps/evaluation/filters/__init__.py +++ b/core/apps/evaluation/filters/__init__.py @@ -1,6 +1,7 @@ from .auto import * # noqa from .customer import * # noqa from .document import * # noqa +from .documentcategory import * # noqa from .history import * # noqa from .movable import * # noqa from .quick import * # noqa diff --git a/core/apps/evaluation/filters/document.py b/core/apps/evaluation/filters/document.py index 28f6b45..fb7c812 100644 --- a/core/apps/evaluation/filters/document.py +++ b/core/apps/evaluation/filters/document.py @@ -1,11 +1,18 @@ from django_filters import rest_framework as filters -from core.apps.evaluation.models import ValuationDocumentModel +from core.apps.evaluation.models import DocumentModel, ValuationDocumentModel class ValuationdocumentFilter(filters.FilterSet): - # name = filters.CharFilter(field_name="name", lookup_expr="icontains") class Meta: model = ValuationDocumentModel fields = [] + + +class DocumentFilter(filters.FilterSet): + + class Meta: + model = DocumentModel + fields = [ + ] diff --git a/core/apps/evaluation/filters/documentcategory.py b/core/apps/evaluation/filters/documentcategory.py new file mode 100644 index 0000000..8daed03 --- /dev/null +++ b/core/apps/evaluation/filters/documentcategory.py @@ -0,0 +1,10 @@ +from django_filters import rest_framework as filters + +from core.apps.evaluation.models import DocumentcategoryModel + + +class DocumentcategoryFilter(filters.FilterSet): + class Meta: + model = DocumentcategoryModel + fields = [ + ] diff --git a/core/apps/evaluation/forms/__init__.py b/core/apps/evaluation/forms/__init__.py index bc24d35..a625148 100644 --- a/core/apps/evaluation/forms/__init__.py +++ b/core/apps/evaluation/forms/__init__.py @@ -1,6 +1,7 @@ from .auto import * # noqa from .customer import * # noqa from .document import * # noqa +from .documentcategory import * # noqa from .history import * # noqa from .movable import * # noqa from .quick import * # noqa diff --git a/core/apps/evaluation/forms/document.py b/core/apps/evaluation/forms/document.py index e566577..a2f6bf4 100644 --- a/core/apps/evaluation/forms/document.py +++ b/core/apps/evaluation/forms/document.py @@ -1,6 +1,6 @@ from django import forms -from core.apps.evaluation.models import ValuationDocumentModel +from core.apps.evaluation.models import DocumentModel, ValuationDocumentModel class ValuationdocumentForm(forms.ModelForm): @@ -8,3 +8,10 @@ class ValuationdocumentForm(forms.ModelForm): class Meta: model = ValuationDocumentModel fields = "__all__" + + +class DocumentForm(forms.ModelForm): + + class Meta: + model = DocumentModel + fields = "__all__" diff --git a/core/apps/evaluation/forms/documentcategory.py b/core/apps/evaluation/forms/documentcategory.py new file mode 100644 index 0000000..aa73aaa --- /dev/null +++ b/core/apps/evaluation/forms/documentcategory.py @@ -0,0 +1,10 @@ +from django import forms + +from core.apps.evaluation.models import DocumentcategoryModel + + +class DocumentcategoryForm(forms.ModelForm): + + class Meta: + model = DocumentcategoryModel + fields = "__all__" diff --git a/core/apps/evaluation/migrations/0027_documentcategorymodel_documentmodel.py b/core/apps/evaluation/migrations/0027_documentcategorymodel_documentmodel.py new file mode 100644 index 0000000..dee3f92 --- /dev/null +++ b/core/apps/evaluation/migrations/0027_documentcategorymodel_documentmodel.py @@ -0,0 +1,52 @@ +# Generated by Django 5.2.7 on 2026-04-03 10:58 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('evaluation', '0026_alter_autoevaluationmodel_form_ownership_and_more'), + ] + + operations = [ + migrations.CreateModel( + name='DocumentcategoryModel', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), + ('label', models.CharField(max_length=255, verbose_name='label')), + ('label_uz', models.CharField(max_length=255, null=True, verbose_name='label')), + ('label_ru', models.CharField(max_length=255, null=True, verbose_name='label')), + ('label_en', models.CharField(max_length=255, null=True, verbose_name='label')), + ('value', models.CharField(max_length=255, verbose_name='value')), + ('value_uz', models.CharField(max_length=255, null=True, verbose_name='value')), + ('value_ru', models.CharField(max_length=255, null=True, verbose_name='value')), + ('value_en', models.CharField(max_length=255, null=True, verbose_name='value')), + ], + options={ + 'verbose_name': 'DocumentcategoryModel', + 'verbose_name_plural': 'DocumentcategoryModels', + 'db_table': 'DocumentCategory', + }, + ), + migrations.CreateModel( + name='DocumentModel', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), + ('title', models.CharField(max_length=255, verbose_name='title')), + ('document', models.FileField(upload_to='evaluation/documents/%Y/%m/', verbose_name='document')), + ('auto_evaluation', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='documents', to='evaluation.autoevaluationmodel', verbose_name='auto evaluation')), + ('category', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='documents', to='evaluation.documentcategorymodel', verbose_name='category')), + ], + options={ + 'verbose_name': 'DocumentModel', + 'verbose_name_plural': 'DocumentModels', + 'db_table': 'Document', + }, + ), + ] diff --git a/core/apps/evaluation/models/__init__.py b/core/apps/evaluation/models/__init__.py index bc24d35..a625148 100644 --- a/core/apps/evaluation/models/__init__.py +++ b/core/apps/evaluation/models/__init__.py @@ -1,6 +1,7 @@ from .auto import * # noqa from .customer import * # noqa from .document import * # noqa +from .documentcategory import * # noqa from .history import * # noqa from .movable import * # noqa from .quick import * # noqa diff --git a/core/apps/evaluation/models/document.py b/core/apps/evaluation/models/document.py index b27bae6..f0b3565 100644 --- a/core/apps/evaluation/models/document.py +++ b/core/apps/evaluation/models/document.py @@ -3,9 +3,10 @@ from django.utils.translation import gettext_lazy as _ from django_core.models import AbstractBaseModel from model_bakery import baker -from .valuation import ValuationModel from core.apps.evaluation.choices.document import DocumentType +from .valuation import ValuationModel + class ValuationDocumentModel(AbstractBaseModel): valuation = models.ForeignKey( @@ -54,3 +55,35 @@ class ValuationDocumentModel(AbstractBaseModel): verbose_name = _("Valuation Document") verbose_name_plural = _("Valuation Documents") ordering = ["-created_at"] + + +class DocumentModel(AbstractBaseModel): + auto_evaluation = models.ForeignKey( + "evaluation.AutoEvaluationModel", + on_delete=models.CASCADE, + related_name="documents", + verbose_name=_("auto evaluation"), + ) + title = models.CharField(verbose_name=_("title"), max_length=255) + document = models.FileField( + verbose_name=_("document"), + upload_to="evaluation/documents/%Y/%m/", + ) + category = models.ForeignKey( + "evaluation.DocumentCategoryModel", + on_delete=models.CASCADE, + related_name="documents", + verbose_name=_("category"), + ) + + def __str__(self): + return str(self.pk) + + @classmethod + def _baker(cls): + return baker.make(cls) + + class Meta: + db_table = "Document" + verbose_name = _("DocumentModel") + verbose_name_plural = _("DocumentModels") diff --git a/core/apps/evaluation/models/documentcategory.py b/core/apps/evaluation/models/documentcategory.py new file mode 100644 index 0000000..217b108 --- /dev/null +++ b/core/apps/evaluation/models/documentcategory.py @@ -0,0 +1,21 @@ +from django.db import models +from django.utils.translation import gettext_lazy as _ +from django_core.models import AbstractBaseModel +from model_bakery import baker + + +class DocumentcategoryModel(AbstractBaseModel): + label = models.CharField(verbose_name=_("label"), max_length=255) + value = models.CharField(verbose_name=_("value"), max_length=255) + + def __str__(self): + return str(self.pk) + + @classmethod + def _baker(cls): + return baker.make(cls) + + class Meta: + db_table = "DocumentCategory" + verbose_name = _("DocumentcategoryModel") + verbose_name_plural = _("DocumentcategoryModels") diff --git a/core/apps/evaluation/permissions/__init__.py b/core/apps/evaluation/permissions/__init__.py index bc24d35..a625148 100644 --- a/core/apps/evaluation/permissions/__init__.py +++ b/core/apps/evaluation/permissions/__init__.py @@ -1,6 +1,7 @@ from .auto import * # noqa from .customer import * # noqa from .document import * # noqa +from .documentcategory import * # noqa from .history import * # noqa from .movable import * # noqa from .quick import * # noqa diff --git a/core/apps/evaluation/permissions/document.py b/core/apps/evaluation/permissions/document.py index 8f71d7f..a441eff 100644 --- a/core/apps/evaluation/permissions/document.py +++ b/core/apps/evaluation/permissions/document.py @@ -10,3 +10,14 @@ class ValuationdocumentPermission(permissions.BasePermission): def has_permission(self, request, view): return True + + +class DocumentPermission(permissions.BasePermission): + + def __init__(self) -> None: ... + + def __call__(self, *args, **kwargs): + return self + + def has_permission(self, request, view): + return True diff --git a/core/apps/evaluation/permissions/documentcategory.py b/core/apps/evaluation/permissions/documentcategory.py new file mode 100644 index 0000000..7a91d4a --- /dev/null +++ b/core/apps/evaluation/permissions/documentcategory.py @@ -0,0 +1,12 @@ +from rest_framework import permissions + + +class DocumentcategoryPermission(permissions.BasePermission): + + def __init__(self) -> None: ... + + def __call__(self, *args, **kwargs): + return self + + def has_permission(self, request, view): + return True diff --git a/core/apps/evaluation/serializers/__init__.py b/core/apps/evaluation/serializers/__init__.py index bc24d35..a625148 100644 --- a/core/apps/evaluation/serializers/__init__.py +++ b/core/apps/evaluation/serializers/__init__.py @@ -1,6 +1,7 @@ from .auto import * # noqa from .customer import * # noqa from .document import * # noqa +from .documentcategory import * # noqa from .history import * # noqa from .movable import * # noqa from .quick import * # noqa diff --git a/core/apps/evaluation/serializers/document/Document.py b/core/apps/evaluation/serializers/document/Document.py new file mode 100644 index 0000000..18d4e38 --- /dev/null +++ b/core/apps/evaluation/serializers/document/Document.py @@ -0,0 +1,42 @@ +from rest_framework import serializers + +from core.apps.evaluation.models import DocumentModel, AutoEvaluationModel, DocumentcategoryModel +from core.apps.evaluation.serializers.documentcategory import ListDocumentcategorySerializer + +class BaseDocumentSerializer(serializers.ModelSerializer): + category = ListDocumentcategorySerializer(read_only=True) + + class Meta: + model = DocumentModel + fields = [ + "id", + "title", + "document", + "category", + "created_at", + "updated_at" + ] + + +class ListDocumentSerializer(BaseDocumentSerializer): + class Meta(BaseDocumentSerializer.Meta): ... + + +class RetrieveDocumentSerializer(BaseDocumentSerializer): + class Meta(BaseDocumentSerializer.Meta): ... + + +class CreateDocumentSerializer(BaseDocumentSerializer): + auto_evaluation = serializers.PrimaryKeyRelatedField(queryset=AutoEvaluationModel.objects.all()) + category = serializers.PrimaryKeyRelatedField(queryset=DocumentcategoryModel.objects.all()) + + class Meta(BaseDocumentSerializer.Meta): + fields = [ + "id", + "title", + "auto_evaluation", + "document", + "category", + "created_at", + "updated_at" + ] diff --git a/core/apps/evaluation/serializers/document/__init__.py b/core/apps/evaluation/serializers/document/__init__.py index 307d410..3316e41 100644 --- a/core/apps/evaluation/serializers/document/__init__.py +++ b/core/apps/evaluation/serializers/document/__init__.py @@ -1 +1,2 @@ +from .Document import * # noqa from .ValuationDocument import * # noqa diff --git a/core/apps/evaluation/serializers/documentcategory/DocumentCategory.py b/core/apps/evaluation/serializers/documentcategory/DocumentCategory.py new file mode 100644 index 0000000..79237e5 --- /dev/null +++ b/core/apps/evaluation/serializers/documentcategory/DocumentCategory.py @@ -0,0 +1,34 @@ +from rest_framework import serializers + +from core.apps.evaluation.models import DocumentcategoryModel + + +class BaseDocumentcategorySerializer(serializers.ModelSerializer): + class Meta: + model = DocumentcategoryModel + fields = [ + "id", + "label", + "value", + "created_at", + "updated_at" + ] + + +class ListDocumentcategorySerializer(BaseDocumentcategorySerializer): + class Meta(BaseDocumentcategorySerializer.Meta): ... + + +class RetrieveDocumentcategorySerializer(BaseDocumentcategorySerializer): + class Meta(BaseDocumentcategorySerializer.Meta): ... + + +# class CreateDocumentcategorySerializer(BaseDocumentcategorySerializer): +# class Meta(BaseDocumentcategorySerializer.Meta): +# fields = [ +# "id", +# "label", +# "value", +# "created_at", +# "updated_at" +# ] diff --git a/core/apps/evaluation/serializers/documentcategory/__init__.py b/core/apps/evaluation/serializers/documentcategory/__init__.py new file mode 100644 index 0000000..4abfd55 --- /dev/null +++ b/core/apps/evaluation/serializers/documentcategory/__init__.py @@ -0,0 +1 @@ +from .DocumentCategory import * # noqa diff --git a/core/apps/evaluation/signals/__init__.py b/core/apps/evaluation/signals/__init__.py index bc24d35..a625148 100644 --- a/core/apps/evaluation/signals/__init__.py +++ b/core/apps/evaluation/signals/__init__.py @@ -1,6 +1,7 @@ from .auto import * # noqa from .customer import * # noqa from .document import * # noqa +from .documentcategory import * # noqa from .history import * # noqa from .movable import * # noqa from .quick import * # noqa diff --git a/core/apps/evaluation/signals/document.py b/core/apps/evaluation/signals/document.py index 16e2648..c24c97c 100644 --- a/core/apps/evaluation/signals/document.py +++ b/core/apps/evaluation/signals/document.py @@ -1,8 +1,12 @@ from django.db.models.signals import post_save from django.dispatch import receiver -from core.apps.evaluation.models import ValuationDocumentModel +from core.apps.evaluation.models import DocumentModel, ValuationDocumentModel @receiver(post_save, sender=ValuationDocumentModel) def ValuationdocumentSignal(sender, instance, created, **kwargs): ... + + +@receiver(post_save, sender=DocumentModel) +def DocumentSignal(sender, instance, created, **kwargs): ... diff --git a/core/apps/evaluation/signals/documentcategory.py b/core/apps/evaluation/signals/documentcategory.py new file mode 100644 index 0000000..f6fef30 --- /dev/null +++ b/core/apps/evaluation/signals/documentcategory.py @@ -0,0 +1,8 @@ +from django.db.models.signals import post_save +from django.dispatch import receiver + +from core.apps.evaluation.models import DocumentcategoryModel + + +@receiver(post_save, sender=DocumentcategoryModel) +def DocumentcategorySignal(sender, instance, created, **kwargs): ... diff --git a/core/apps/evaluation/tests/__init__.py b/core/apps/evaluation/tests/__init__.py index bc24d35..a625148 100644 --- a/core/apps/evaluation/tests/__init__.py +++ b/core/apps/evaluation/tests/__init__.py @@ -1,6 +1,7 @@ from .auto import * # noqa from .customer import * # noqa from .document import * # noqa +from .documentcategory import * # noqa from .history import * # noqa from .movable import * # noqa from .quick import * # noqa diff --git a/core/apps/evaluation/tests/document/__init__.py b/core/apps/evaluation/tests/document/__init__.py index 6d4c049..b5223cb 100644 --- a/core/apps/evaluation/tests/document/__init__.py +++ b/core/apps/evaluation/tests/document/__init__.py @@ -1 +1,2 @@ +from .test_Document import * # noqa from .test_ValuationDocument import * # noqa diff --git a/core/apps/evaluation/tests/document/test_Document.py b/core/apps/evaluation/tests/document/test_Document.py new file mode 100644 index 0000000..d6a5aac --- /dev/null +++ b/core/apps/evaluation/tests/document/test_Document.py @@ -0,0 +1,101 @@ +import pytest +from django.urls import reverse +from rest_framework.test import APIClient + +from core.apps.evaluation.models import DocumentModel + + +@pytest.fixture +def instance(db): + return DocumentModel._baker() + + +@pytest.fixture +def api_client(instance): + client = APIClient() + ##client.force_authenticate(user=instance.user) + return client, instance + + +@pytest.fixture +def data(api_client): + client, instance = api_client + return ( + { + "list": reverse("Document-list"), + "retrieve": reverse("Document-detail", kwargs={"pk": instance.pk}), + "retrieve-not-found": reverse("Document-detail", kwargs={"pk": 1000}), + }, + client, + instance, + ) + + +@pytest.mark.django_db +def test_list(data): + urls, client, _ = data + response = client.get(urls["list"]) + data_resp = response.json() + assert response.status_code == 200 + assert data_resp["status"] is True + + +@pytest.mark.django_db +def test_retrieve(data): + urls, client, _ = data + response = client.get(urls["retrieve"]) + data_resp = response.json() + assert response.status_code == 200 + assert data_resp["status"] is True + + +@pytest.mark.django_db +def test_retrieve_not_found(data): + urls, client, _ = data + response = client.get(urls["retrieve-not-found"]) + data_resp = response.json() + assert response.status_code == 404 + assert data_resp["status"] is False + + +# @pytest.mark.django_db +# def test_create(data): +# urls, client, _ = data +# response = client.post(urls["list"], data={"name": "test"}) +# assert response.json()["status"] is True +# assert response.status_code == 201 + + +# @pytest.mark.django_db +# def test_update(data): +# urls, client, _ = data +# response = client.patch(urls["retrieve"], data={"name": "updated"}) +# assert response.json()["status"] is True +# assert response.status_code == 200 +# +# # verify updated value +# response = client.get(urls["retrieve"]) +# assert response.json()["status"] is True +# assert response.status_code == 200 +# assert response.json()["data"]["name"] == "updated" + + +# @pytest.mark.django_db +# def test_partial_update(): +# urls, client, _ = data +# response = client.patch(urls["retrieve"], data={"name": "updated"}) +# assert response.json()["status"] is True +# assert response.status_code == 200 +# +# # verify updated value +# response = client.get(urls["retrieve"]) +# assert response.json()["status"] is True +# assert response.status_code == 200 +# assert response.json()["data"]["name"] == "updated" + + +# @pytest.mark.django_db +# def test_destroy(data): +# urls, client, _ = data +# response = client.delete(urls["retrieve"]) +# assert response.status_code == 204 diff --git a/core/apps/evaluation/tests/documentcategory/__init__.py b/core/apps/evaluation/tests/documentcategory/__init__.py new file mode 100644 index 0000000..c0fe54a --- /dev/null +++ b/core/apps/evaluation/tests/documentcategory/__init__.py @@ -0,0 +1 @@ +from .test_DocumentCategory import * # noqa diff --git a/core/apps/evaluation/tests/documentcategory/test_DocumentCategory.py b/core/apps/evaluation/tests/documentcategory/test_DocumentCategory.py new file mode 100644 index 0000000..8d7bbed --- /dev/null +++ b/core/apps/evaluation/tests/documentcategory/test_DocumentCategory.py @@ -0,0 +1,101 @@ +import pytest +from django.urls import reverse +from rest_framework.test import APIClient + +from core.apps.evaluation.models import DocumentcategoryModel + + +@pytest.fixture +def instance(db): + return DocumentcategoryModel._baker() + + +@pytest.fixture +def api_client(instance): + client = APIClient() + ##client.force_authenticate(user=instance.user) + return client, instance + + +@pytest.fixture +def data(api_client): + client, instance = api_client + return ( + { + "list": reverse("DocumentCategory-list"), + "retrieve": reverse("DocumentCategory-detail", kwargs={"pk": instance.pk}), + "retrieve-not-found": reverse("DocumentCategory-detail", kwargs={"pk": 1000}), + }, + client, + instance, + ) + + +@pytest.mark.django_db +def test_list(data): + urls, client, _ = data + response = client.get(urls["list"]) + data_resp = response.json() + assert response.status_code == 200 + assert data_resp["status"] is True + + +@pytest.mark.django_db +def test_retrieve(data): + urls, client, _ = data + response = client.get(urls["retrieve"]) + data_resp = response.json() + assert response.status_code == 200 + assert data_resp["status"] is True + + +@pytest.mark.django_db +def test_retrieve_not_found(data): + urls, client, _ = data + response = client.get(urls["retrieve-not-found"]) + data_resp = response.json() + assert response.status_code == 404 + assert data_resp["status"] is False + + +# @pytest.mark.django_db +# def test_create(data): +# urls, client, _ = data +# response = client.post(urls["list"], data={"name": "test"}) +# assert response.json()["status"] is True +# assert response.status_code == 201 + + +# @pytest.mark.django_db +# def test_update(data): +# urls, client, _ = data +# response = client.patch(urls["retrieve"], data={"name": "updated"}) +# assert response.json()["status"] is True +# assert response.status_code == 200 +# +# # verify updated value +# response = client.get(urls["retrieve"]) +# assert response.json()["status"] is True +# assert response.status_code == 200 +# assert response.json()["data"]["name"] == "updated" + + +# @pytest.mark.django_db +# def test_partial_update(): +# urls, client, _ = data +# response = client.patch(urls["retrieve"], data={"name": "updated"}) +# assert response.json()["status"] is True +# assert response.status_code == 200 +# +# # verify updated value +# response = client.get(urls["retrieve"]) +# assert response.json()["status"] is True +# assert response.status_code == 200 +# assert response.json()["data"]["name"] == "updated" + + +# @pytest.mark.django_db +# def test_destroy(data): +# urls, client, _ = data +# response = client.delete(urls["retrieve"]) +# assert response.status_code == 204 diff --git a/core/apps/evaluation/translation/__init__.py b/core/apps/evaluation/translation/__init__.py index bc24d35..a625148 100644 --- a/core/apps/evaluation/translation/__init__.py +++ b/core/apps/evaluation/translation/__init__.py @@ -1,6 +1,7 @@ from .auto import * # noqa from .customer import * # noqa from .document import * # noqa +from .documentcategory import * # noqa from .history import * # noqa from .movable import * # noqa from .quick import * # noqa diff --git a/core/apps/evaluation/translation/document.py b/core/apps/evaluation/translation/document.py index 5cbba53..d01d9a6 100644 --- a/core/apps/evaluation/translation/document.py +++ b/core/apps/evaluation/translation/document.py @@ -1,8 +1,13 @@ from modeltranslation.translator import TranslationOptions, register -from core.apps.evaluation.models import ValuationDocumentModel +from core.apps.evaluation.models import DocumentModel, ValuationDocumentModel @register(ValuationDocumentModel) class ValuationdocumentTranslation(TranslationOptions): fields = [] + + +@register(DocumentModel) +class DocumentTranslation(TranslationOptions): + fields = [] diff --git a/core/apps/evaluation/translation/documentcategory.py b/core/apps/evaluation/translation/documentcategory.py new file mode 100644 index 0000000..d3d9244 --- /dev/null +++ b/core/apps/evaluation/translation/documentcategory.py @@ -0,0 +1,8 @@ +from modeltranslation.translator import TranslationOptions, register + +from core.apps.evaluation.models import DocumentcategoryModel + + +@register(DocumentcategoryModel) +class DocumentcategoryTranslation(TranslationOptions): + fields = ["label", "value"] diff --git a/core/apps/evaluation/urls.py b/core/apps/evaluation/urls.py index 120be3a..64b5f11 100644 --- a/core/apps/evaluation/urls.py +++ b/core/apps/evaluation/urls.py @@ -2,10 +2,13 @@ from django.urls import include, path from rest_framework.routers import DefaultRouter from .views import ( + AdminEvaluationrequestView, AutoEvaluationHistoryView, AutoEvaluationView, CustomerView, DeterminedValueView, + DocumentCategoryView, + DocumentView, EvaluationPurposeView, EvaluationReportView, EvaluationrequestView, @@ -20,10 +23,11 @@ from .views import ( ValuationDocumentView, ValuationView, VehicleView, - AdminEvaluationrequestView, ) router = DefaultRouter() +router.register("document-category", DocumentCategoryView, basename="DocumentCategory") +router.register("document", DocumentView, basename="Document") router.register("auto-evaluation-history", AutoEvaluationHistoryView, basename="auto-evaluation-history") router.register("quick-evaluation-history", QuickEvaluationHistoryView, basename="quick-evaluation-history") router.register("determined-value", DeterminedValueView, basename="determined-value") diff --git a/core/apps/evaluation/validators/__init__.py b/core/apps/evaluation/validators/__init__.py index bc24d35..a625148 100644 --- a/core/apps/evaluation/validators/__init__.py +++ b/core/apps/evaluation/validators/__init__.py @@ -1,6 +1,7 @@ from .auto import * # noqa from .customer import * # noqa from .document import * # noqa +from .documentcategory import * # noqa from .history import * # noqa from .movable import * # noqa from .quick import * # noqa diff --git a/core/apps/evaluation/validators/document.py b/core/apps/evaluation/validators/document.py index 7bee7f6..852b40c 100644 --- a/core/apps/evaluation/validators/document.py +++ b/core/apps/evaluation/validators/document.py @@ -6,3 +6,10 @@ class ValuationdocumentValidator: def __call__(self): return True + + +class DocumentValidator: + def __init__(self): ... + + def __call__(self): + return True diff --git a/core/apps/evaluation/validators/documentcategory.py b/core/apps/evaluation/validators/documentcategory.py new file mode 100644 index 0000000..96b7780 --- /dev/null +++ b/core/apps/evaluation/validators/documentcategory.py @@ -0,0 +1,8 @@ +# from django.core.exceptions import ValidationError + + +class DocumentcategoryValidator: + def __init__(self): ... + + def __call__(self): + return True diff --git a/core/apps/evaluation/views/__init__.py b/core/apps/evaluation/views/__init__.py index bc24d35..a625148 100644 --- a/core/apps/evaluation/views/__init__.py +++ b/core/apps/evaluation/views/__init__.py @@ -1,6 +1,7 @@ from .auto import * # noqa from .customer import * # noqa from .document import * # noqa +from .documentcategory import * # noqa from .history import * # noqa from .movable import * # noqa from .quick import * # noqa diff --git a/core/apps/evaluation/views/document.py b/core/apps/evaluation/views/document.py index d74407a..977e835 100644 --- a/core/apps/evaluation/views/document.py +++ b/core/apps/evaluation/views/document.py @@ -1,12 +1,20 @@ +from django.shortcuts import get_object_or_404 from django_core.mixins import BaseViewSetMixin from drf_spectacular.utils import extend_schema +from rest_framework.exceptions import NotFound, PermissionDenied from rest_framework.permissions import AllowAny -from rest_framework.viewsets import ReadOnlyModelViewSet +from rest_framework.viewsets import ReadOnlyModelViewSet, ModelViewSet +from rest_framework.parsers import FormParser, MultiPartParser +from rest_framework.decorators import action +from rest_framework.response import Response -from core.apps.evaluation.models import ValuationDocumentModel +from core.apps.evaluation.models import DocumentModel, ValuationDocumentModel, AutoEvaluationModel from core.apps.evaluation.serializers.document import ( + CreateDocumentSerializer, CreateValuationdocumentSerializer, + ListDocumentSerializer, ListValuationdocumentSerializer, + RetrieveDocumentSerializer, RetrieveValuationdocumentSerializer, ) @@ -23,3 +31,35 @@ class ValuationDocumentView(BaseViewSetMixin, ReadOnlyModelViewSet): "retrieve": RetrieveValuationdocumentSerializer, "create": CreateValuationdocumentSerializer, } + + +@extend_schema(tags=["Document"]) +class DocumentView(BaseViewSetMixin, ModelViewSet): + queryset = DocumentModel.objects.all() + serializer_class = ListDocumentSerializer + permission_classes = [AllowAny] + parser_classes = [FormParser, MultiPartParser] + + action_permission_classes = {} + action_serializer_class = { + "list": ListDocumentSerializer, + "retrieve": RetrieveDocumentSerializer, + "create": CreateDocumentSerializer, + } + + @extend_schema(summary="Auto evaluation documents.", description="get auto evaluation documents.") + @action(methods=["GET"], detail=False, url_path=r"auto_evaluation/(?P\d+)") + def auto_evaluation(self, request, auto_evaluation_id=None): + try: + auto_evaluation = get_object_or_404(AutoEvaluationModel, id=auto_evaluation_id) + documents = DocumentModel.objects.filter(auto_evaluation=auto_evaluation) + page = self.paginate_queryset(documents) + if page is not None: + serializer = ListDocumentSerializer(page, many=True) + return self.get_paginated_response(serializer.data) + serializer = ListDocumentSerializer(documents, many=True) + return Response(serializer.data) + except AutoEvaluationModel.DoesNotExist: + raise NotFound("Auto evaluation not found") + except Exception as e: + raise PermissionDenied(e) diff --git a/core/apps/evaluation/views/documentcategory.py b/core/apps/evaluation/views/documentcategory.py new file mode 100644 index 0000000..d9c4a27 --- /dev/null +++ b/core/apps/evaluation/views/documentcategory.py @@ -0,0 +1,24 @@ +from django_core.mixins import BaseViewSetMixin +from drf_spectacular.utils import extend_schema +from rest_framework.permissions import AllowAny +from rest_framework.viewsets import ReadOnlyModelViewSet + +from core.apps.evaluation.models import DocumentcategoryModel +from core.apps.evaluation.serializers.documentcategory import ( + ListDocumentcategorySerializer, + RetrieveDocumentcategorySerializer, +) + + +@extend_schema(tags=["DocumentCategory"]) +class DocumentCategoryView(BaseViewSetMixin, ReadOnlyModelViewSet): + queryset = DocumentcategoryModel.objects.all() + serializer_class = ListDocumentcategorySerializer + permission_classes = [AllowAny] + + action_permission_classes = {} + action_serializer_class = { + "list": ListDocumentcategorySerializer, + "retrieve": RetrieveDocumentcategorySerializer, + # "create": CreateDocumentcategorySerializer, + }