feat(evaluation): baholash modellari yaratildi (auto, ko'chmas mulk, ko'char mulk, tezkor, hisobot)
This commit is contained in:
@@ -3,5 +3,6 @@ from .customer import * # noqa
|
||||
from .movable import * # noqa
|
||||
from .quick import * # noqa
|
||||
from .real_estate import * # noqa
|
||||
from .report import * # noqa
|
||||
from .valuation import * # noqa
|
||||
from .vehicle import * # noqa
|
||||
|
||||
12
core/apps/evaluation/admin/report.py
Normal file
12
core/apps/evaluation/admin/report.py
Normal file
@@ -0,0 +1,12 @@
|
||||
from django.contrib import admin
|
||||
from unfold.admin import ModelAdmin
|
||||
|
||||
from core.apps.evaluation.models import EvaluationReportModel
|
||||
|
||||
|
||||
@admin.register(EvaluationReportModel)
|
||||
class EvaluationreportAdmin(ModelAdmin):
|
||||
list_display = (
|
||||
"id",
|
||||
"__str__",
|
||||
)
|
||||
@@ -3,5 +3,6 @@ from .customer import * # noqa
|
||||
from .movable import * # noqa
|
||||
from .quick import * # noqa
|
||||
from .real_estate import * # noqa
|
||||
from .report import * # noqa
|
||||
from .valuation import * # noqa
|
||||
from .vehicle import * # noqa
|
||||
|
||||
13
core/apps/evaluation/filters/report.py
Normal file
13
core/apps/evaluation/filters/report.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from django_filters import rest_framework as filters
|
||||
|
||||
from core.apps.evaluation.models import EvaluationReportModel
|
||||
|
||||
|
||||
class EvaluationreportFilter(filters.FilterSet):
|
||||
# name = filters.CharFilter(field_name="name", lookup_expr="icontains")
|
||||
|
||||
class Meta:
|
||||
model = EvaluationReportModel
|
||||
fields = [
|
||||
"name",
|
||||
]
|
||||
@@ -3,5 +3,6 @@ from .customer import * # noqa
|
||||
from .movable import * # noqa
|
||||
from .quick import * # noqa
|
||||
from .real_estate import * # noqa
|
||||
from .report import * # noqa
|
||||
from .valuation import * # noqa
|
||||
from .vehicle import * # noqa
|
||||
|
||||
10
core/apps/evaluation/forms/report.py
Normal file
10
core/apps/evaluation/forms/report.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from django import forms
|
||||
|
||||
from core.apps.evaluation.models import EvaluationReportModel
|
||||
|
||||
|
||||
class EvaluationreportForm(forms.ModelForm):
|
||||
|
||||
class Meta:
|
||||
model = EvaluationReportModel
|
||||
fields = "__all__"
|
||||
@@ -0,0 +1,36 @@
|
||||
# Generated by Django 5.2.7 on 2026-02-18 12:34
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('evaluation', '0007_quickevaluationmodel'),
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='EvaluationReportModel',
|
||||
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)),
|
||||
('report_number', models.CharField(max_length=100, unique=True, verbose_name='report number')),
|
||||
('final_value', models.DecimalField(decimal_places=2, max_digits=15, verbose_name='final value')),
|
||||
('report_file', models.FileField(blank=True, null=True, upload_to='evaluation/reports/', verbose_name='report file')),
|
||||
('conclusion_text', models.TextField(blank=True, verbose_name='conclusion text')),
|
||||
('approved_at', models.DateTimeField(blank=True, null=True, verbose_name='approved at')),
|
||||
('evaluator', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='reports', to=settings.AUTH_USER_MODEL, verbose_name='evaluator')),
|
||||
('valuation', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='report', to='evaluation.valuationmodel', verbose_name='valuation')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Evaluation Report',
|
||||
'verbose_name_plural': 'Evaluation Reports',
|
||||
'db_table': 'EvaluationReport',
|
||||
},
|
||||
),
|
||||
]
|
||||
@@ -3,5 +3,6 @@ from .customer import * # noqa
|
||||
from .movable import * # noqa
|
||||
from .quick import * # noqa
|
||||
from .real_estate import * # noqa
|
||||
from .report import * # noqa
|
||||
from .valuation import * # noqa
|
||||
from .vehicle import * # noqa
|
||||
|
||||
48
core/apps/evaluation/models/report.py
Normal file
48
core/apps/evaluation/models/report.py
Normal file
@@ -0,0 +1,48 @@
|
||||
from django.db import models
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django_core.models import AbstractBaseModel
|
||||
from model_bakery import baker
|
||||
|
||||
|
||||
from .valuation import ValuationModel
|
||||
|
||||
|
||||
class EvaluationReportModel(AbstractBaseModel):
|
||||
valuation = models.OneToOneField(
|
||||
ValuationModel,
|
||||
on_delete=models.CASCADE,
|
||||
related_name="report",
|
||||
verbose_name=_("valuation"),
|
||||
)
|
||||
evaluator = models.ForeignKey(
|
||||
"accounts.User",
|
||||
on_delete=models.PROTECT,
|
||||
related_name="reports",
|
||||
verbose_name=_("evaluator"),
|
||||
)
|
||||
report_number = models.CharField(
|
||||
verbose_name=_("report number"), max_length=100, unique=True
|
||||
)
|
||||
final_value = models.DecimalField(
|
||||
verbose_name=_("final value"), max_digits=15, decimal_places=2
|
||||
)
|
||||
report_file = models.FileField(
|
||||
verbose_name=_("report file"), upload_to="evaluation/reports/", blank=True, null=True
|
||||
)
|
||||
conclusion_text = models.TextField(verbose_name=_("conclusion text"), blank=True)
|
||||
approved_at = models.DateTimeField(
|
||||
verbose_name=_("approved at"), blank=True, null=True
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return f"Report #{self.report_number} for {self.valuation}"
|
||||
|
||||
@classmethod
|
||||
def _baker(cls):
|
||||
return baker.make(cls)
|
||||
|
||||
class Meta:
|
||||
db_table = "EvaluationReport"
|
||||
verbose_name = _("Evaluation Report")
|
||||
verbose_name_plural = _("Evaluation Reports")
|
||||
|
||||
@@ -3,5 +3,6 @@ from .customer import * # noqa
|
||||
from .movable import * # noqa
|
||||
from .quick import * # noqa
|
||||
from .real_estate import * # noqa
|
||||
from .report import * # noqa
|
||||
from .valuation import * # noqa
|
||||
from .vehicle import * # noqa
|
||||
|
||||
12
core/apps/evaluation/permissions/report.py
Normal file
12
core/apps/evaluation/permissions/report.py
Normal file
@@ -0,0 +1,12 @@
|
||||
from rest_framework import permissions
|
||||
|
||||
|
||||
class EvaluationreportPermission(permissions.BasePermission):
|
||||
|
||||
def __init__(self) -> None: ...
|
||||
|
||||
def __call__(self, *args, **kwargs):
|
||||
return self
|
||||
|
||||
def has_permission(self, request, view):
|
||||
return True
|
||||
@@ -3,5 +3,6 @@ from .customer import * # noqa
|
||||
from .movable import * # noqa
|
||||
from .quick import * # noqa
|
||||
from .real_estate import * # noqa
|
||||
from .report import * # noqa
|
||||
from .valuation import * # noqa
|
||||
from .vehicle import * # noqa
|
||||
|
||||
39
core/apps/evaluation/serializers/report/EvaluationReport.py
Normal file
39
core/apps/evaluation/serializers/report/EvaluationReport.py
Normal file
@@ -0,0 +1,39 @@
|
||||
from rest_framework import serializers
|
||||
|
||||
from core.apps.evaluation.models import EvaluationReportModel
|
||||
|
||||
|
||||
class BaseEvaluationreportSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = EvaluationReportModel
|
||||
fields = [
|
||||
"id",
|
||||
"valuation",
|
||||
"evaluator",
|
||||
"report_number",
|
||||
"final_value",
|
||||
"report_file",
|
||||
"conclusion_text",
|
||||
"approved_at",
|
||||
]
|
||||
|
||||
|
||||
class ListEvaluationreportSerializer(BaseEvaluationreportSerializer):
|
||||
class Meta(BaseEvaluationreportSerializer.Meta): ...
|
||||
|
||||
|
||||
class RetrieveEvaluationreportSerializer(BaseEvaluationreportSerializer):
|
||||
class Meta(BaseEvaluationreportSerializer.Meta): ...
|
||||
|
||||
|
||||
class CreateEvaluationreportSerializer(BaseEvaluationreportSerializer):
|
||||
class Meta(BaseEvaluationreportSerializer.Meta):
|
||||
fields = [
|
||||
"id",
|
||||
"valuation",
|
||||
"evaluator",
|
||||
"report_number",
|
||||
"final_value",
|
||||
"report_file",
|
||||
"conclusion_text",
|
||||
]
|
||||
1
core/apps/evaluation/serializers/report/__init__.py
Normal file
1
core/apps/evaluation/serializers/report/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from .EvaluationReport import * # noqa
|
||||
@@ -3,5 +3,6 @@ from .customer import * # noqa
|
||||
from .movable import * # noqa
|
||||
from .quick import * # noqa
|
||||
from .real_estate import * # noqa
|
||||
from .report import * # noqa
|
||||
from .valuation import * # noqa
|
||||
from .vehicle import * # noqa
|
||||
|
||||
8
core/apps/evaluation/signals/report.py
Normal file
8
core/apps/evaluation/signals/report.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 EvaluationReportModel
|
||||
|
||||
|
||||
@receiver(post_save, sender=EvaluationReportModel)
|
||||
def EvaluationreportSignal(sender, instance, created, **kwargs): ...
|
||||
@@ -3,5 +3,6 @@ from .customer import * # noqa
|
||||
from .movable import * # noqa
|
||||
from .quick import * # noqa
|
||||
from .real_estate import * # noqa
|
||||
from .report import * # noqa
|
||||
from .valuation import * # noqa
|
||||
from .vehicle import * # noqa
|
||||
|
||||
1
core/apps/evaluation/tests/report/__init__.py
Normal file
1
core/apps/evaluation/tests/report/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from .test_EvaluationReport import * # noqa
|
||||
101
core/apps/evaluation/tests/report/test_EvaluationReport.py
Normal file
101
core/apps/evaluation/tests/report/test_EvaluationReport.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 EvaluationReportModel
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def instance(db):
|
||||
return EvaluationReportModel._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("evaluation-report-list"),
|
||||
"retrieve": reverse("evaluation-report-detail", kwargs={"pk": instance.pk}),
|
||||
"retrieve-not-found": reverse("evaluation-report-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
|
||||
@@ -3,5 +3,6 @@ from .customer import * # noqa
|
||||
from .movable import * # noqa
|
||||
from .quick import * # noqa
|
||||
from .real_estate import * # noqa
|
||||
from .report import * # noqa
|
||||
from .valuation import * # noqa
|
||||
from .vehicle import * # noqa
|
||||
|
||||
8
core/apps/evaluation/translation/report.py
Normal file
8
core/apps/evaluation/translation/report.py
Normal file
@@ -0,0 +1,8 @@
|
||||
from modeltranslation.translator import TranslationOptions, register
|
||||
|
||||
from core.apps.evaluation.models import EvaluationReportModel
|
||||
|
||||
|
||||
@register(EvaluationReportModel)
|
||||
class EvaluationreportTranslation(TranslationOptions):
|
||||
fields = []
|
||||
@@ -4,6 +4,7 @@ from rest_framework.routers import DefaultRouter
|
||||
from .views import (
|
||||
AutoEvaluationView,
|
||||
CustomerView,
|
||||
EvaluationReportView,
|
||||
MovablePropertyEvaluationView,
|
||||
PropertyOwnerView,
|
||||
QuickEvaluationView,
|
||||
@@ -13,6 +14,7 @@ from .views import (
|
||||
)
|
||||
|
||||
router = DefaultRouter()
|
||||
router.register("evaluation-report", EvaluationReportView, basename="evaluation-report")
|
||||
router.register("quick-evaluation", QuickEvaluationView, basename="quick-evaluation")
|
||||
router.register("movable-property-evaluation", MovablePropertyEvaluationView, basename="movable-property-evaluation")
|
||||
router.register("real-estate-evaluation", RealEstateEvaluationView, basename="real-estate-evaluation")
|
||||
|
||||
@@ -3,5 +3,6 @@ from .customer import * # noqa
|
||||
from .movable import * # noqa
|
||||
from .quick import * # noqa
|
||||
from .real_estate import * # noqa
|
||||
from .report import * # noqa
|
||||
from .valuation import * # noqa
|
||||
from .vehicle import * # noqa
|
||||
|
||||
8
core/apps/evaluation/validators/report.py
Normal file
8
core/apps/evaluation/validators/report.py
Normal file
@@ -0,0 +1,8 @@
|
||||
# from django.core.exceptions import ValidationError
|
||||
|
||||
|
||||
class EvaluationreportValidator:
|
||||
def __init__(self): ...
|
||||
|
||||
def __call__(self):
|
||||
return True
|
||||
@@ -3,5 +3,6 @@ from .customer import * # noqa
|
||||
from .movable import * # noqa
|
||||
from .quick import * # noqa
|
||||
from .real_estate import * # noqa
|
||||
from .report import * # noqa
|
||||
from .valuation import * # noqa
|
||||
from .vehicle import * # noqa
|
||||
|
||||
25
core/apps/evaluation/views/report.py
Normal file
25
core/apps/evaluation/views/report.py
Normal file
@@ -0,0 +1,25 @@
|
||||
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 EvaluationReportModel
|
||||
from core.apps.evaluation.serializers.report import (
|
||||
CreateEvaluationreportSerializer,
|
||||
ListEvaluationreportSerializer,
|
||||
RetrieveEvaluationreportSerializer,
|
||||
)
|
||||
|
||||
|
||||
@extend_schema(tags=["EvaluationReport"])
|
||||
class EvaluationReportView(BaseViewSetMixin, ReadOnlyModelViewSet):
|
||||
queryset = EvaluationReportModel.objects.all()
|
||||
serializer_class = ListEvaluationreportSerializer
|
||||
permission_classes = [AllowAny]
|
||||
|
||||
action_permission_classes = {}
|
||||
action_serializer_class = {
|
||||
"list": ListEvaluationreportSerializer,
|
||||
"retrieve": RetrieveEvaluationreportSerializer,
|
||||
"create": CreateEvaluationreportSerializer,
|
||||
}
|
||||
Reference in New Issue
Block a user