movable-model qoshildi bu (Ko'char mulk) modeli to'liq va optimallashgan holda tayyor! #12

Merged
husanjon merged 1 commits from feat/evaluation-movable-model into main 2026-02-13 12:58:25 +00:00
27 changed files with 349 additions and 2 deletions
Showing only changes of commit 2cb094cbd3 - Show all commits

View File

@@ -1,5 +1,6 @@
from .auto import * # noqa from .auto import * # noqa
from .customer import * # noqa from .customer import * # noqa
from .movable import * # noqa
from .real_estate import * # noqa from .real_estate import * # noqa
from .valuation import * # noqa from .valuation import * # noqa
from .vehicle import * # noqa from .vehicle import * # noqa

View File

@@ -0,0 +1,12 @@
from django.contrib import admin
from unfold.admin import ModelAdmin
from core.apps.evaluation.models import MovablePropertyEvaluationModel
@admin.register(MovablePropertyEvaluationModel)
class MovablepropertyevaluationAdmin(ModelAdmin):
list_display = (
"id",
"__str__",
)

View File

@@ -0,0 +1,19 @@
from django.db import models
from django.utils.translation import gettext_lazy as _
class MovablePropertyCategory(models.TextChoices):
EQUIPMENT = "equipment", _("Equipment")
MACHINERY = "machinery", _("Machinery")
FURNITURE = "furniture", _("Furniture")
ELECTRONICS = "electronics", _("Electronics")
COMMODITY = "commodity", _("Commodity/Goods")
OTHER = "other", _("Other")
class MovablePropertyCondition(models.TextChoices):
NEW = "new", _("New")
GOOD = "good", _("Good")
AVERAGE = "average", _("Average")
POOR = "poor", _("Poor/Needs repair")
SCRAP = "scrap", _("Scrap")

View File

@@ -1,5 +1,6 @@
from .auto import * # noqa from .auto import * # noqa
from .customer import * # noqa from .customer import * # noqa
from .movable import * # noqa
from .real_estate import * # noqa from .real_estate import * # noqa
from .valuation import * # noqa from .valuation import * # noqa
from .vehicle import * # noqa from .vehicle import * # noqa

View File

@@ -0,0 +1,13 @@
# from django_filters import rest_framework as filters
# from core.apps.evaluation.models import MovablePropertyEvaluationModel
# class MovablepropertyevaluationFilter(filters.FilterSet):
# # name = filters.CharFilter(field_name="name", lookup_expr="icontains")
# class Meta:
# model = MovablePropertyEvaluationModel
# fields = [
# "name",
# ]

View File

@@ -1,5 +1,6 @@
from .auto import * # noqa from .auto import * # noqa
from .customer import * # noqa from .customer import * # noqa
from .movable import * # noqa
from .real_estate import * # noqa from .real_estate import * # noqa
from .valuation import * # noqa from .valuation import * # noqa
from .vehicle import * # noqa from .vehicle import * # noqa

View File

@@ -0,0 +1,10 @@
from django import forms
from core.apps.evaluation.models import MovablePropertyEvaluationModel
class MovablepropertyevaluationForm(forms.ModelForm):
class Meta:
model = MovablePropertyEvaluationModel
fields = "__all__"

View File

@@ -0,0 +1,34 @@
# Generated by Django 5.2.7 on 2026-02-13 12:51
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('evaluation', '0005_realestateevaluationmodel'),
]
operations = [
migrations.CreateModel(
name='MovablePropertyEvaluationModel',
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)),
('property_name', models.CharField(max_length=255, verbose_name='property name')),
('property_category', models.CharField(choices=[('equipment', 'Equipment'), ('machinery', 'Machinery'), ('furniture', 'Furniture'), ('electronics', 'Electronics'), ('commodity', 'Commodity/Goods'), ('other', 'Other')], default='other', max_length=50, verbose_name='property category')),
('serial_number', models.CharField(blank=True, max_length=100, null=True, verbose_name='serial number')),
('manufacture_year', models.IntegerField(blank=True, null=True, verbose_name='manufacture year')),
('condition', models.CharField(blank=True, choices=[('new', 'New'), ('good', 'Good'), ('average', 'Average'), ('poor', 'Poor/Needs repair'), ('scrap', 'Scrap')], max_length=50, null=True, verbose_name='condition')),
('quantity', models.IntegerField(default=1, verbose_name='quantity')),
('valuation', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='movable_property_detail', to='evaluation.valuationmodel', verbose_name='valuation')),
],
options={
'verbose_name': 'Movable Property Evaluation',
'verbose_name_plural': 'Movable Property Evaluations',
'db_table': 'MovablePropertyEvaluation',
},
),
]

View File

@@ -1,7 +1,8 @@
from .auto import * # noqa from .auto import * # noqa
from .real_estate import * # noqa
from .customer import * # noqa from .customer import * # noqa
from .movable import * # noqa
from .real_estate import * # noqa from .real_estate import * # noqa
from .movable import * # noqa
from .valuation import * # noqa from .valuation import * # noqa
from .vehicle import * # noqa from .vehicle import * # noqa

View File

@@ -0,0 +1,54 @@
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.movable import (
MovablePropertyCategory,
MovablePropertyCondition,
)
class MovablePropertyEvaluationModel(AbstractBaseModel):
valuation = models.OneToOneField(
ValuationModel,
on_delete=models.CASCADE,
related_name="movable_property_detail",
verbose_name=_("valuation"),
)
property_name = models.CharField(verbose_name=_("property name"), max_length=255)
property_category = models.CharField(
verbose_name=_("property category"),
max_length=50,
choices=MovablePropertyCategory.choices,
default=MovablePropertyCategory.OTHER,
)
serial_number = models.CharField(
verbose_name=_("serial number"), max_length=100, blank=True, null=True
)
manufacture_year = models.IntegerField(
verbose_name=_("manufacture year"), blank=True, null=True
)
condition = models.CharField(
verbose_name=_("condition"),
max_length=50,
choices=MovablePropertyCondition.choices,
blank=True,
null=True,
)
quantity = models.IntegerField(verbose_name=_("quantity"), default=1)
def __str__(self):
return f"Movable Property Evaluation: {self.property_name} ({self.valuation})"
@classmethod
def _baker(cls):
return baker.make(cls)
class Meta:
db_table = "MovablePropertyEvaluation"
verbose_name = _("Movable Property Evaluation")
verbose_name_plural = _("Movable Property Evaluations")

View File

@@ -1,5 +1,6 @@
from .auto import * # noqa from .auto import * # noqa
from .customer import * # noqa from .customer import * # noqa
from .movable import * # noqa
from .real_estate import * # noqa from .real_estate import * # noqa
from .valuation import * # noqa from .valuation import * # noqa
from .vehicle import * # noqa from .vehicle import * # noqa

View File

@@ -0,0 +1,12 @@
from rest_framework import permissions
class MovablepropertyevaluationPermission(permissions.BasePermission):
def __init__(self) -> None: ...
def __call__(self, *args, **kwargs):
return self
def has_permission(self, request, view):
return True

View File

@@ -1,5 +1,6 @@
from .auto import * # noqa from .auto import * # noqa
from .customer import * # noqa from .customer import * # noqa
from .movable import * # noqa
from .real_estate import * # noqa from .real_estate import * # noqa
from .valuation import * # noqa from .valuation import * # noqa
from .vehicle import * # noqa from .vehicle import * # noqa

View File

@@ -0,0 +1,28 @@
from rest_framework import serializers
from core.apps.evaluation.models import MovablePropertyEvaluationModel
class BaseMovablepropertyevaluationSerializer(serializers.ModelSerializer):
class Meta:
model = MovablePropertyEvaluationModel
fields = [
"id",
# "name",
]
class ListMovablepropertyevaluationSerializer(BaseMovablepropertyevaluationSerializer):
class Meta(BaseMovablepropertyevaluationSerializer.Meta): ...
class RetrieveMovablepropertyevaluationSerializer(BaseMovablepropertyevaluationSerializer):
class Meta(BaseMovablepropertyevaluationSerializer.Meta): ...
class CreateMovablepropertyevaluationSerializer(BaseMovablepropertyevaluationSerializer):
class Meta(BaseMovablepropertyevaluationSerializer.Meta):
fields = [
"id",
# "name",
]

View File

@@ -0,0 +1 @@
from .MovablePropertyEvaluation import * # noqa

View File

@@ -1,5 +1,6 @@
from .auto import * # noqa from .auto import * # noqa
from .customer import * # noqa from .customer import * # noqa
from .movable import * # noqa
from .real_estate import * # noqa from .real_estate import * # noqa
from .valuation import * # noqa from .valuation import * # noqa
from .vehicle import * # noqa from .vehicle import * # noqa

View File

@@ -0,0 +1,8 @@
from django.db.models.signals import post_save
from django.dispatch import receiver
from core.apps.evaluation.models import MovablePropertyEvaluationModel
@receiver(post_save, sender=MovablePropertyEvaluationModel)
def MovablepropertyevaluationSignal(sender, instance, created, **kwargs): ...

View File

@@ -1,5 +1,6 @@
from .auto import * # noqa from .auto import * # noqa
from .customer import * # noqa from .customer import * # noqa
from .movable import * # noqa
from .real_estate import * # noqa from .real_estate import * # noqa
from .valuation import * # noqa from .valuation import * # noqa
from .vehicle import * # noqa from .vehicle import * # noqa

View File

@@ -0,0 +1 @@
from .test_MovablePropertyEvaluation import * # noqa

View File

@@ -0,0 +1,101 @@
import pytest
from django.urls import reverse
from rest_framework.test import APIClient
from core.apps.evaluation.models import MovablePropertyEvaluationModel
@pytest.fixture
def instance(db):
return MovablePropertyEvaluationModel._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("movable-property-evaluation-list"),
"retrieve": reverse("movable-property-evaluation-detail", kwargs={"pk": instance.pk}),
"retrieve-not-found": reverse("movable-property-evaluation-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

View File

@@ -1,5 +1,6 @@
from .auto import * # noqa from .auto import * # noqa
from .customer import * # noqa from .customer import * # noqa
from .movable import * # noqa
from .real_estate import * # noqa from .real_estate import * # noqa
from .valuation import * # noqa from .valuation import * # noqa
from .vehicle import * # noqa from .vehicle import * # noqa

View File

@@ -0,0 +1,8 @@
from modeltranslation.translator import TranslationOptions, register
from core.apps.evaluation.models import MovablePropertyEvaluationModel
@register(MovablePropertyEvaluationModel)
class MovablepropertyevaluationTranslation(TranslationOptions):
fields = []

View File

@@ -4,6 +4,7 @@ from rest_framework.routers import DefaultRouter
from .views import ( from .views import (
AutoEvaluationView, AutoEvaluationView,
CustomerView, CustomerView,
MovablePropertyEvaluationView,
PropertyOwnerView, PropertyOwnerView,
RealEstateEvaluationView, RealEstateEvaluationView,
ValuationView, ValuationView,
@@ -11,6 +12,7 @@ from .views import (
) )
router = DefaultRouter() router = DefaultRouter()
router.register("movable-property-evaluation", MovablePropertyEvaluationView, basename="movable-property-evaluation")
router.register("real-estate-evaluation", RealEstateEvaluationView, basename="real-estate-evaluation") router.register("real-estate-evaluation", RealEstateEvaluationView, basename="real-estate-evaluation")
router.register("auto-evaluation", AutoEvaluationView, basename="auto-evaluation") router.register("auto-evaluation", AutoEvaluationView, basename="auto-evaluation")
router.register("vehicle", VehicleView, basename="vehicle") router.register("vehicle", VehicleView, basename="vehicle")

View File

@@ -1,5 +1,6 @@
from .auto import * # noqa from .auto import * # noqa
from .customer import * # noqa from .customer import * # noqa
from .movable import * # noqa
from .real_estate import * # noqa from .real_estate import * # noqa
from .valuation import * # noqa from .valuation import * # noqa
from .vehicle import * # noqa from .vehicle import * # noqa

View File

@@ -0,0 +1,8 @@
# from django.core.exceptions import ValidationError
class MovablepropertyevaluationValidator:
def __init__(self): ...
def __call__(self):
return True

View File

@@ -1,5 +1,6 @@
from .auto import * # noqa from .auto import * # noqa
from .customer import * # noqa from .customer import * # noqa
from .movable import * # noqa
from .real_estate import * # noqa from .real_estate import * # noqa
from .valuation import * # noqa from .valuation import * # noqa
from .vehicle import * # noqa from .vehicle import * # noqa

View 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 MovablePropertyEvaluationModel
from core.apps.evaluation.serializers.movable import (
CreateMovablepropertyevaluationSerializer,
ListMovablepropertyevaluationSerializer,
RetrieveMovablepropertyevaluationSerializer,
)
@extend_schema(tags=["MovablePropertyEvaluation"])
class MovablePropertyEvaluationView(BaseViewSetMixin, ReadOnlyModelViewSet):
queryset = MovablePropertyEvaluationModel.objects.all()
serializer_class = ListMovablepropertyevaluationSerializer
permission_classes = [AllowAny]
action_permission_classes = {}
action_serializer_class = {
"list": ListMovablepropertyevaluationSerializer,
"retrieve": RetrieveMovablepropertyevaluationSerializer,
"create": CreateMovablepropertyevaluationSerializer,
}