Merge pull request 'ValuationDocumentModel' (#15) from feat/evaluation-document-model into main
All checks were successful
Deploy to Production / build-and-deploy (push) Successful in 3m18s
All checks were successful
Deploy to Production / build-and-deploy (push) Successful in 3m18s
Reviewed-on: #15
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from .auto import * # noqa
|
||||
from .customer import * # noqa
|
||||
from .document import * # noqa
|
||||
from .movable import * # noqa
|
||||
from .quick import * # noqa
|
||||
from .real_estate import * # noqa
|
||||
|
||||
12
core/apps/evaluation/admin/document.py
Normal file
12
core/apps/evaluation/admin/document.py
Normal file
@@ -0,0 +1,12 @@
|
||||
from django.contrib import admin
|
||||
from unfold.admin import ModelAdmin
|
||||
|
||||
from core.apps.evaluation.models import ValuationDocumentModel
|
||||
|
||||
|
||||
@admin.register(ValuationDocumentModel)
|
||||
class ValuationdocumentAdmin(ModelAdmin):
|
||||
list_display = (
|
||||
"id",
|
||||
"__str__",
|
||||
)
|
||||
13
core/apps/evaluation/choices/document.py
Normal file
13
core/apps/evaluation/choices/document.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from django.db import models
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
|
||||
class DocumentType(models.TextChoices):
|
||||
CERTIFICATE = "certificate", _("Certificate")
|
||||
PASSPORT = "passport", _("Passport")
|
||||
TECH_PASSPORT = "tech_passport", _("Tech Passport")
|
||||
CADASTRAL = "cadastral", _("Cadastral Document")
|
||||
PHOTO = "photo", _("Photo")
|
||||
CONTRACT = "contract", _("Contract")
|
||||
POWER_OF_ATTORNEY = "power_of_attorney", _("Power of Attorney")
|
||||
OTHER = "other", _("Other")
|
||||
@@ -1,5 +1,6 @@
|
||||
from .auto import * # noqa
|
||||
from .customer import * # noqa
|
||||
from .document import * # noqa
|
||||
from .movable import * # noqa
|
||||
from .quick import * # noqa
|
||||
from .real_estate import * # noqa
|
||||
|
||||
13
core/apps/evaluation/filters/document.py
Normal file
13
core/apps/evaluation/filters/document.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from django_filters import rest_framework as filters
|
||||
|
||||
from core.apps.evaluation.models import ValuationDocumentModel
|
||||
|
||||
|
||||
class ValuationdocumentFilter(filters.FilterSet):
|
||||
# name = filters.CharFilter(field_name="name", lookup_expr="icontains")
|
||||
|
||||
class Meta:
|
||||
model = ValuationDocumentModel
|
||||
fields = [
|
||||
"name",
|
||||
]
|
||||
@@ -1,5 +1,6 @@
|
||||
from .auto import * # noqa
|
||||
from .customer import * # noqa
|
||||
from .document import * # noqa
|
||||
from .movable import * # noqa
|
||||
from .quick import * # noqa
|
||||
from .real_estate import * # noqa
|
||||
|
||||
10
core/apps/evaluation/forms/document.py
Normal file
10
core/apps/evaluation/forms/document.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from django import forms
|
||||
|
||||
from core.apps.evaluation.models import ValuationDocumentModel
|
||||
|
||||
|
||||
class ValuationdocumentForm(forms.ModelForm):
|
||||
|
||||
class Meta:
|
||||
model = ValuationDocumentModel
|
||||
fields = "__all__"
|
||||
@@ -0,0 +1,36 @@
|
||||
# Generated by Django 5.2.7 on 2026-02-18 12:54
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('evaluation', '0008_evaluationreportmodel'),
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='ValuationDocumentModel',
|
||||
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)),
|
||||
('document_type', models.CharField(choices=[('certificate', 'Certificate'), ('passport', 'Passport'), ('tech_passport', 'Tech Passport'), ('cadastral', 'Cadastral Document'), ('photo', 'Photo'), ('contract', 'Contract'), ('power_of_attorney', 'Power of Attorney'), ('other', 'Other')], default='other', max_length=50, verbose_name='document type')),
|
||||
('title', models.CharField(blank=True, max_length=255, verbose_name='title')),
|
||||
('file', models.FileField(upload_to='evaluation/documents/%Y/%m/', verbose_name='file')),
|
||||
('description', models.TextField(blank=True, verbose_name='description')),
|
||||
('uploaded_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='uploaded_documents', to=settings.AUTH_USER_MODEL, verbose_name='uploaded by')),
|
||||
('valuation', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='documents', to='evaluation.valuationmodel', verbose_name='valuation')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Valuation Document',
|
||||
'verbose_name_plural': 'Valuation Documents',
|
||||
'db_table': 'ValuationDocument',
|
||||
'ordering': ['-created_at'],
|
||||
},
|
||||
),
|
||||
]
|
||||
@@ -1,5 +1,6 @@
|
||||
from .auto import * # noqa
|
||||
from .customer import * # noqa
|
||||
from .document import * # noqa
|
||||
from .movable import * # noqa
|
||||
from .quick import * # noqa
|
||||
from .real_estate import * # noqa
|
||||
|
||||
56
core/apps/evaluation/models/document.py
Normal file
56
core/apps/evaluation/models/document.py
Normal file
@@ -0,0 +1,56 @@
|
||||
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
|
||||
from core.apps.evaluation.choices.document import DocumentType
|
||||
|
||||
|
||||
class ValuationDocumentModel(AbstractBaseModel):
|
||||
valuation = models.ForeignKey(
|
||||
ValuationModel,
|
||||
on_delete=models.CASCADE,
|
||||
related_name="documents",
|
||||
verbose_name=_("valuation"),
|
||||
)
|
||||
document_type = models.CharField(
|
||||
verbose_name=_("document type"),
|
||||
max_length=50,
|
||||
choices=DocumentType.choices,
|
||||
default=DocumentType.OTHER,
|
||||
)
|
||||
title = models.CharField(
|
||||
verbose_name=_("title"),
|
||||
max_length=255,
|
||||
blank=True,
|
||||
)
|
||||
file = models.FileField(
|
||||
verbose_name=_("file"),
|
||||
upload_to="evaluation/documents/%Y/%m/",
|
||||
)
|
||||
uploaded_by = models.ForeignKey(
|
||||
"accounts.User",
|
||||
on_delete=models.SET_NULL,
|
||||
null=True,
|
||||
blank=True,
|
||||
related_name="uploaded_documents",
|
||||
verbose_name=_("uploaded by"),
|
||||
)
|
||||
description = models.TextField(
|
||||
verbose_name=_("description"),
|
||||
blank=True,
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.get_document_type_display()} — {self.valuation}"
|
||||
|
||||
@classmethod
|
||||
def _baker(cls):
|
||||
return baker.make(cls)
|
||||
|
||||
class Meta:
|
||||
db_table = "ValuationDocument"
|
||||
verbose_name = _("Valuation Document")
|
||||
verbose_name_plural = _("Valuation Documents")
|
||||
ordering = ["-created_at"]
|
||||
@@ -1,5 +1,6 @@
|
||||
from .auto import * # noqa
|
||||
from .customer import * # noqa
|
||||
from .document import * # noqa
|
||||
from .movable import * # noqa
|
||||
from .quick import * # noqa
|
||||
from .real_estate import * # noqa
|
||||
|
||||
12
core/apps/evaluation/permissions/document.py
Normal file
12
core/apps/evaluation/permissions/document.py
Normal file
@@ -0,0 +1,12 @@
|
||||
from rest_framework import permissions
|
||||
|
||||
|
||||
class ValuationdocumentPermission(permissions.BasePermission):
|
||||
|
||||
def __init__(self) -> None: ...
|
||||
|
||||
def __call__(self, *args, **kwargs):
|
||||
return self
|
||||
|
||||
def has_permission(self, request, view):
|
||||
return True
|
||||
@@ -1,5 +1,6 @@
|
||||
from .auto import * # noqa
|
||||
from .customer import * # noqa
|
||||
from .document import * # noqa
|
||||
from .movable import * # noqa
|
||||
from .quick import * # noqa
|
||||
from .real_estate import * # noqa
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
from rest_framework import serializers
|
||||
|
||||
from core.apps.evaluation.models import ValuationDocumentModel
|
||||
|
||||
|
||||
class BaseValuationdocumentSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = ValuationDocumentModel
|
||||
fields = [
|
||||
"id",
|
||||
"document_type",
|
||||
]
|
||||
|
||||
|
||||
class ListValuationdocumentSerializer(BaseValuationdocumentSerializer):
|
||||
class Meta(BaseValuationdocumentSerializer.Meta): ...
|
||||
|
||||
|
||||
class RetrieveValuationdocumentSerializer(BaseValuationdocumentSerializer):
|
||||
class Meta(BaseValuationdocumentSerializer.Meta): ...
|
||||
|
||||
|
||||
class CreateValuationdocumentSerializer(BaseValuationdocumentSerializer):
|
||||
class Meta(BaseValuationdocumentSerializer.Meta):
|
||||
fields = [
|
||||
"id",
|
||||
"document_type",
|
||||
]
|
||||
1
core/apps/evaluation/serializers/document/__init__.py
Normal file
1
core/apps/evaluation/serializers/document/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from .ValuationDocument import * # noqa
|
||||
@@ -1,5 +1,6 @@
|
||||
from .auto import * # noqa
|
||||
from .customer import * # noqa
|
||||
from .document import * # noqa
|
||||
from .movable import * # noqa
|
||||
from .quick import * # noqa
|
||||
from .real_estate import * # noqa
|
||||
|
||||
8
core/apps/evaluation/signals/document.py
Normal file
8
core/apps/evaluation/signals/document.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 ValuationDocumentModel
|
||||
|
||||
|
||||
@receiver(post_save, sender=ValuationDocumentModel)
|
||||
def ValuationdocumentSignal(sender, instance, created, **kwargs): ...
|
||||
@@ -1,5 +1,6 @@
|
||||
from .auto import * # noqa
|
||||
from .customer import * # noqa
|
||||
from .document import * # noqa
|
||||
from .movable import * # noqa
|
||||
from .quick import * # noqa
|
||||
from .real_estate import * # noqa
|
||||
|
||||
1
core/apps/evaluation/tests/document/__init__.py
Normal file
1
core/apps/evaluation/tests/document/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from .test_ValuationDocument import * # noqa
|
||||
101
core/apps/evaluation/tests/document/test_ValuationDocument.py
Normal file
101
core/apps/evaluation/tests/document/test_ValuationDocument.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 ValuationDocumentModel
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def instance(db):
|
||||
return ValuationDocumentModel._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("valuation-document-list"),
|
||||
"retrieve": reverse("valuation-document-detail", kwargs={"pk": instance.pk}),
|
||||
"retrieve-not-found": reverse("valuation-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,5 +1,6 @@
|
||||
from .auto import * # noqa
|
||||
from .customer import * # noqa
|
||||
from .document import * # noqa
|
||||
from .movable import * # noqa
|
||||
from .quick import * # noqa
|
||||
from .real_estate import * # noqa
|
||||
|
||||
8
core/apps/evaluation/translation/document.py
Normal file
8
core/apps/evaluation/translation/document.py
Normal file
@@ -0,0 +1,8 @@
|
||||
from modeltranslation.translator import TranslationOptions, register
|
||||
|
||||
from core.apps.evaluation.models import ValuationDocumentModel
|
||||
|
||||
|
||||
@register(ValuationDocumentModel)
|
||||
class ValuationdocumentTranslation(TranslationOptions):
|
||||
fields = []
|
||||
@@ -9,11 +9,13 @@ from .views import (
|
||||
PropertyOwnerView,
|
||||
QuickEvaluationView,
|
||||
RealEstateEvaluationView,
|
||||
ValuationDocumentView,
|
||||
ValuationView,
|
||||
VehicleView,
|
||||
)
|
||||
|
||||
router = DefaultRouter()
|
||||
router.register("valuation-document", ValuationDocumentView, basename="valuation-document")
|
||||
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")
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from .auto import * # noqa
|
||||
from .customer import * # noqa
|
||||
from .document import * # noqa
|
||||
from .movable import * # noqa
|
||||
from .quick import * # noqa
|
||||
from .real_estate import * # noqa
|
||||
|
||||
8
core/apps/evaluation/validators/document.py
Normal file
8
core/apps/evaluation/validators/document.py
Normal file
@@ -0,0 +1,8 @@
|
||||
# from django.core.exceptions import ValidationError
|
||||
|
||||
|
||||
class ValuationdocumentValidator:
|
||||
def __init__(self): ...
|
||||
|
||||
def __call__(self):
|
||||
return True
|
||||
@@ -1,5 +1,6 @@
|
||||
from .auto import * # noqa
|
||||
from .customer import * # noqa
|
||||
from .document import * # noqa
|
||||
from .movable import * # noqa
|
||||
from .quick import * # noqa
|
||||
from .real_estate import * # noqa
|
||||
|
||||
25
core/apps/evaluation/views/document.py
Normal file
25
core/apps/evaluation/views/document.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 ValuationDocumentModel
|
||||
from core.apps.evaluation.serializers.document import (
|
||||
CreateValuationdocumentSerializer,
|
||||
ListValuationdocumentSerializer,
|
||||
RetrieveValuationdocumentSerializer,
|
||||
)
|
||||
|
||||
|
||||
@extend_schema(tags=["ValuationDocument"])
|
||||
class ValuationDocumentView(BaseViewSetMixin, ReadOnlyModelViewSet):
|
||||
queryset = ValuationDocumentModel.objects.all()
|
||||
serializer_class = ListValuationdocumentSerializer
|
||||
permission_classes = [AllowAny]
|
||||
|
||||
action_permission_classes = {}
|
||||
action_serializer_class = {
|
||||
"list": ListValuationdocumentSerializer,
|
||||
"retrieve": RetrieveValuationdocumentSerializer,
|
||||
"create": CreateValuationdocumentSerializer,
|
||||
}
|
||||
Reference in New Issue
Block a user