Files
state-corp-backend/src/apps/form_5/models.py
Aleksandr Meshchriakov 345b1d0cc8
Some checks failed
CI/CD Pipeline / Run Tests (push) Failing after 45s
CI/CD Pipeline / Code Quality Checks (push) Failing after 48s
CI/CD Pipeline / Build Docker Images (push) Has been skipped
CI/CD Pipeline / Push to Gitea Registry (push) Has been skipped
CI/CD Pipeline / Deploy to Server (push) Has been skipped
Add initial implementations for forms and organization apps with serializers, factories, and admin configurations
2026-03-28 18:23:06 +01:00

212 lines
6.0 KiB
Python

"""
Модели формы Ф-5 (Инвентаризация оборудования).
Содержит:
- FormF5Record - запись формы Ф-5 (детальная информация по единице оборудования)
"""
import uuid
from apps.core.mixins import ReportingPeriodMixin, TimestampMixin
from apps.organization.models import Organization
from django.db import models
from django.utils.translation import gettext_lazy as _
class FormF5Record(ReportingPeriodMixin, TimestampMixin, models.Model):
"""
Запись формы Ф-5 (Инвентаризация оборудования).
Детальная информация по каждой единице оборудования.
"""
id = models.UUIDField(
primary_key=True,
default=uuid.uuid4,
editable=False,
verbose_name=_("ID"),
)
organization = models.ForeignKey(
Organization,
on_delete=models.CASCADE,
related_name="form_f5_records",
verbose_name=_("организация"),
)
load_batch = models.PositiveIntegerField(
_("номер загрузки"),
db_index=True,
help_text=_("Идентификатор пакета загрузки"),
)
# === Идентификация оборудования ===
equipment_id = models.CharField(
_("идентификационный код"),
max_length=50,
blank=True,
default="",
)
inventory_number = models.CharField(
_("инвентарный номер"),
max_length=50,
blank=True,
default="",
)
name = models.CharField(
_("наименование оборудования"),
max_length=500,
blank=True,
default="",
)
model = models.CharField(
_("модель"),
max_length=200,
blank=True,
default="",
)
# === Производитель ===
manufacturer = models.CharField(
_("производитель"),
max_length=300,
blank=True,
default="",
)
country_origin = models.CharField(
_("страна происхождения"),
max_length=100,
blank=True,
default="",
)
is_domestic = models.BooleanField(
_("отечественное производство"),
null=True,
blank=True,
)
# === Технические характеристики ===
year_manufacture = models.PositiveIntegerField(
_("год выпуска"),
null=True,
blank=True,
)
has_cnc = models.BooleanField(
_("наличие ЧПУ"),
null=True,
blank=True,
)
equipment_type = models.CharField(
_("тип оборудования"),
max_length=200,
blank=True,
default="",
)
equipment_category = models.CharField(
_("категория оборудования"),
max_length=200,
blank=True,
default="",
)
# === Эксплуатация ===
commissioning_date = models.DateField(
_("дата ввода в эксплуатацию"),
null=True,
blank=True,
)
location = models.CharField(
_("местонахождение"),
max_length=300,
blank=True,
default="",
)
production_site = models.CharField(
_("производственный участок"),
max_length=200,
blank=True,
default="",
)
# === Состояние и использование ===
utilization_rate = models.DecimalField(
_("коэффициент использования"),
max_digits=5,
decimal_places=2,
null=True,
blank=True,
)
physical_wear_percent = models.DecimalField(
_("фактический износ, %"),
max_digits=5,
decimal_places=2,
null=True,
blank=True,
)
is_operational = models.BooleanField(
_("в рабочем состоянии"),
null=True,
blank=True,
)
requires_repair = models.BooleanField(
_("требует ремонта"),
null=True,
blank=True,
)
requires_replacement = models.BooleanField(
_("требует замены"),
null=True,
blank=True,
)
# === Стоимость ===
initial_cost = models.DecimalField(
_("первоначальная стоимость"),
max_digits=20,
decimal_places=2,
null=True,
blank=True,
)
residual_value = models.DecimalField(
_("остаточная стоимость"),
max_digits=20,
decimal_places=2,
null=True,
blank=True,
)
# === Дополнительная информация ===
notes = models.TextField(
_("примечания"),
blank=True,
default="",
)
class Meta:
verbose_name = _("запись Ф-5")
verbose_name_plural = _("записи Ф-5")
ordering = ["-created_at"]
indexes = [
models.Index(fields=["organization", "load_batch"]),
models.Index(fields=["load_batch"]),
models.Index(fields=["equipment_id"]),
models.Index(fields=["inventory_number"]),
models.Index(
fields=[
"organization",
"report_year",
"report_quarter",
"is_active_version",
]
),
models.Index(fields=["report_year", "report_quarter", "is_active_version"]),
]
constraints = [
models.CheckConstraint(
check=models.Q(report_quarter__isnull=True)
| models.Q(report_quarter__gte=1, report_quarter__lte=4),
name="form_5_f5_report_quarter_range",
),
]
def __str__(self) -> str:
return f"Ф-5: {self.name or self.inventory_number} ({self.organization.name})"