Add initial implementations for forms and organization apps with serializers, factories, and admin configurations
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

This commit is contained in:
2026-03-28 18:23:06 +01:00
parent 8ed3e1175c
commit 345b1d0cc8
201 changed files with 15097 additions and 6691 deletions

View File

@@ -16,7 +16,9 @@ class FormF5RecordFactory(factory.django.DjangoModelFactory):
model = FormF5Record
organization = factory.SubFactory(OrganizationFactory)
load_batch = factory.LazyAttribute(lambda _: fake.uuid4())
load_batch = factory.Sequence(lambda n: n + 1)
report_year = 2026
report_quarter = 1
# Идентификация
equipment_id = factory.LazyAttribute(lambda _: fake.numerify("EQ-######"))
@@ -30,15 +32,39 @@ class FormF5RecordFactory(factory.django.DjangoModelFactory):
is_domestic = factory.LazyAttribute(lambda _: fake.boolean())
# Характеристики
year_manufacture = factory.LazyAttribute(lambda _: fake.random_int(min=1990, max=2024))
year_manufacture = factory.LazyAttribute(
lambda _: fake.random_int(min=1990, max=2024)
)
has_cnc = factory.LazyAttribute(lambda _: fake.boolean())
equipment_type = factory.LazyAttribute(lambda _: fake.random_element(["Токарный", "Фрезерный", "Шлифовальный", "Сверлильный"]))
equipment_type = factory.LazyAttribute(
lambda _: fake.random_element(
["Токарный", "Фрезерный", "Шлифовальный", "Сверлильный"]
)
)
# Состояние
utilization_rate = factory.LazyAttribute(lambda _: fake.pydecimal(min_value=0, max_value=100, left_digits=3, right_digits=2))
physical_wear_percent = factory.LazyAttribute(lambda _: fake.pydecimal(min_value=0, max_value=100, left_digits=3, right_digits=2))
is_operational = factory.LazyAttribute(lambda _: fake.boolean(chance_of_getting_true=85))
utilization_rate = factory.LazyAttribute(
lambda _: fake.pydecimal(
min_value=0, max_value=100, left_digits=3, right_digits=2
)
)
physical_wear_percent = factory.LazyAttribute(
lambda _: fake.pydecimal(
min_value=0, max_value=100, left_digits=3, right_digits=2
)
)
is_operational = factory.LazyAttribute(
lambda _: fake.boolean(chance_of_getting_true=85)
)
# Стоимость
initial_cost = factory.LazyAttribute(lambda _: fake.pydecimal(min_value=100000, max_value=100000000, left_digits=12, right_digits=2))
residual_value = factory.LazyAttribute(lambda _: fake.pydecimal(min_value=10000, max_value=50000000, left_digits=12, right_digits=2))
initial_cost = factory.LazyAttribute(
lambda _: fake.pydecimal(
min_value=100000, max_value=100000000, left_digits=12, right_digits=2
)
)
residual_value = factory.LazyAttribute(
lambda _: fake.pydecimal(
min_value=10000, max_value=50000000, left_digits=12, right_digits=2
)
)

View File

@@ -19,7 +19,10 @@ class FormF5RecordModelTest(TestCase):
def test_record_str_representation(self):
"""Test string representation."""
expected = f"Ф-5: {self.record.organization} - {self.record.equipment_id}"
expected = (
f"Ф-5: {self.record.name or self.record.inventory_number} "
f"({self.record.organization.name})"
)
self.assertEqual(str(self.record), expected)
def test_organization_relationship(self):
@@ -40,7 +43,7 @@ class FormF5RecordModelTest(TestCase):
def test_decimal_fields_precision(self):
"""Test decimal fields precision."""
field = self.record._meta.get_field("initial_cost")
self.assertEqual(field.max_digits, 18)
self.assertEqual(field.max_digits, 20)
self.assertEqual(field.decimal_places, 2)
def test_load_batch_index(self):

View File

@@ -23,7 +23,7 @@ class FormF5ServiceTest(TestCase):
def test_get_by_load_batch(self):
"""Test getting records by load batch."""
batch_id = "test-batch-f5"
batch_id = 105
FormF5RecordFactory.create(load_batch=batch_id)
FormF5RecordFactory.create(load_batch=batch_id)
@@ -32,10 +32,10 @@ class FormF5ServiceTest(TestCase):
def test_delete_by_load_batch(self):
"""Test deleting records by load batch."""
batch_id = "delete-batch-f5"
batch_id = 305
FormF5RecordFactory.create(load_batch=batch_id)
FormF5RecordFactory.create(load_batch=batch_id)
other = FormF5RecordFactory.create(load_batch="keep-batch")
other = FormF5RecordFactory.create(load_batch=405)
count = FormF5Service.delete_by_load_batch(batch_id)
self.assertEqual(count, 2)
@@ -44,27 +44,52 @@ class FormF5ServiceTest(TestCase):
self.assertTrue(FormF5Record.objects.filter(pk=other.pk).exists())
def test_same_batch_period_keeps_multiple_active_rows(self):
"""F-5 may contain multiple active rows in one report batch."""
org = OrganizationFactory.create()
first = FormF5Service.create_versioned_record(
organization=org,
load_batch=701,
report_year=2026,
report_quarter=1,
equipment_id="EQ-001",
name="Станок 1",
)
second = FormF5Service.create_versioned_record(
organization=org,
load_batch=701,
report_year=2026,
report_quarter=1,
equipment_id="EQ-002",
name="Станок 2",
)
first.refresh_from_db()
second.refresh_from_db()
self.assertTrue(first.is_active_version)
self.assertTrue(second.is_active_version)
class FormF5ParserTest(TestCase):
"""Tests for FormF5Parser."""
def test_get_column_mappings_returns_mappings(self):
"""Test get_column_mappings returns correct mappings."""
parser = FormF5Parser()
parser = FormF5Parser(report_year=2026, report_quarter=1)
mappings = parser.get_column_mappings()
self.assertIsInstance(mappings, list)
self.assertTrue(len(mappings) > 0)
field_names = [m.field_name for m in mappings]
self.assertIn("inn", field_names)
self.assertIn("equipment_id", field_names)
self.assertIn("name", field_names)
def test_create_record_creates_organization(self):
"""Test create_record creates organization if not exists."""
parser = FormF5Parser()
parser.load_batch = "test-batch"
parser = FormF5Parser(report_year=2026, report_quarter=1)
parser.load_batch = 505
row_data = {
"inn": "5234567890",
@@ -77,3 +102,5 @@ class FormF5ParserTest(TestCase):
self.assertIsNotNone(record)
self.assertEqual(record.organization.inn, "5234567890")
self.assertEqual(record.report_year, 2026)
self.assertEqual(record.report_quarter, 1)