Merge pull request 'behruz' (#43) from behruz into main
All checks were successful
Deploy to Production / build-and-deploy (push) Successful in 1m54s
All checks were successful
Deploy to Production / build-and-deploy (push) Successful in 1m54s
Reviewed-on: #43
This commit is contained in:
@@ -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"),
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
@@ -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'),
|
||||
),
|
||||
]
|
||||
@@ -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
|
||||
|
||||
@@ -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__",
|
||||
)
|
||||
|
||||
57
core/apps/evaluation/admin/documentcategory.py
Normal file
57
core/apps/evaluation/admin/documentcategory.py
Normal file
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -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 = [
|
||||
]
|
||||
|
||||
10
core/apps/evaluation/filters/documentcategory.py
Normal file
10
core/apps/evaluation/filters/documentcategory.py
Normal file
@@ -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 = [
|
||||
]
|
||||
@@ -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
|
||||
|
||||
@@ -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__"
|
||||
|
||||
10
core/apps/evaluation/forms/documentcategory.py
Normal file
10
core/apps/evaluation/forms/documentcategory.py
Normal file
@@ -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__"
|
||||
@@ -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',
|
||||
},
|
||||
),
|
||||
]
|
||||
@@ -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
|
||||
|
||||
@@ -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")
|
||||
|
||||
21
core/apps/evaluation/models/documentcategory.py
Normal file
21
core/apps/evaluation/models/documentcategory.py
Normal file
@@ -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")
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
12
core/apps/evaluation/permissions/documentcategory.py
Normal file
12
core/apps/evaluation/permissions/documentcategory.py
Normal file
@@ -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
|
||||
@@ -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
|
||||
|
||||
42
core/apps/evaluation/serializers/document/Document.py
Normal file
42
core/apps/evaluation/serializers/document/Document.py
Normal file
@@ -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"
|
||||
]
|
||||
@@ -1 +1,2 @@
|
||||
from .Document import * # noqa
|
||||
from .ValuationDocument import * # noqa
|
||||
|
||||
@@ -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"
|
||||
# ]
|
||||
@@ -0,0 +1 @@
|
||||
from .DocumentCategory import * # noqa
|
||||
@@ -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
|
||||
|
||||
@@ -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): ...
|
||||
|
||||
8
core/apps/evaluation/signals/documentcategory.py
Normal file
8
core/apps/evaluation/signals/documentcategory.py
Normal file
@@ -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): ...
|
||||
@@ -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
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
from .test_Document import * # noqa
|
||||
from .test_ValuationDocument import * # noqa
|
||||
|
||||
101
core/apps/evaluation/tests/document/test_Document.py
Normal file
101
core/apps/evaluation/tests/document/test_Document.py
Normal file
@@ -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
|
||||
1
core/apps/evaluation/tests/documentcategory/__init__.py
Normal file
1
core/apps/evaluation/tests/documentcategory/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from .test_DocumentCategory import * # noqa
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -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 = []
|
||||
|
||||
8
core/apps/evaluation/translation/documentcategory.py
Normal file
8
core/apps/evaluation/translation/documentcategory.py
Normal file
@@ -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"]
|
||||
@@ -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")
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -6,3 +6,10 @@ class ValuationdocumentValidator:
|
||||
|
||||
def __call__(self):
|
||||
return True
|
||||
|
||||
|
||||
class DocumentValidator:
|
||||
def __init__(self): ...
|
||||
|
||||
def __call__(self):
|
||||
return True
|
||||
|
||||
8
core/apps/evaluation/validators/documentcategory.py
Normal file
8
core/apps/evaluation/validators/documentcategory.py
Normal file
@@ -0,0 +1,8 @@
|
||||
# from django.core.exceptions import ValidationError
|
||||
|
||||
|
||||
class DocumentcategoryValidator:
|
||||
def __init__(self): ...
|
||||
|
||||
def __call__(self):
|
||||
return True
|
||||
@@ -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
|
||||
|
||||
@@ -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<auto_evaluation_id>\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)
|
||||
|
||||
24
core/apps/evaluation/views/documentcategory.py
Normal file
24
core/apps/evaluation/views/documentcategory.py
Normal file
@@ -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,
|
||||
}
|
||||
Reference in New Issue
Block a user