feat: add test finance history
All checks were successful
CI/CD Pipeline / Quality Gate (push) Successful in 32s
CI/CD Pipeline / Build and Push Images (push) Successful in 21s
CI/CD Pipeline / Internal Notify (push) Successful in 0s
CI/CD Pipeline / Deploy Dev via Compose (push) Successful in 34s

This commit is contained in:
2026-08-09 13:47:25 +02:00
parent 661e857f53
commit 27768edcea
2 changed files with 132 additions and 38 deletions

View File

@@ -33,6 +33,7 @@ from organizations.source_cache import invalidate_source_data_cache
from organizations.source_groups import SOURCE_GROUP_DESCRIPTORS
TEST_COMPANY_COUNT = 20
TEST_FINANCIAL_HISTORY_YEARS = 4
TEST_COMPANY_NAMESPACE = UUID("59b36ae9-bcf8-4b7c-b77a-77578f485a01")
TEST_RECORD_PREFIX = "mostovik-test-company"
@@ -670,44 +671,81 @@ class TestCompanyDatasetService:
@staticmethod
def _refresh_financial_lines(*, record, legacy_report, index: int) -> None:
report_year = timezone.localdate().year
expected = {
("1", "1600", "Баланс (актив)", 10_000_000 + index * 100_000),
("1", "1300", "Капитал и резервы", 4_000_000 + index * 50_000),
("2", "2110", "Выручка", 20_000_000 + index * 200_000),
("2", "2400", "Чистая прибыль", 2_000_000 + index * 25_000),
}
expected_keys = []
for form_code, line_code, line_name, period_end in expected:
expected_keys.append((form_code, line_code, report_year))
OrganizationSourceFinancialLine.objects.update_or_create(
source_record=record,
form_code=form_code,
line_code=line_code,
year=report_year,
defaults={
current_year = timezone.localdate().year
report_years = range(
current_year - TEST_FINANCIAL_HISTORY_YEARS + 1,
current_year + 1,
)
expected = (
(
"1",
"1600",
"Баланс (актив)",
10_000_000 + index * 100_000,
300_000 + index * 2_000,
),
(
"1",
"1300",
"Капитал и резервы",
4_000_000 + index * 50_000,
120_000 + index * 1_000,
),
(
"2",
"2110",
"Выручка",
20_000_000 + index * 200_000,
750_000 + index * 5_000,
),
(
"2",
"2400",
"Чистая прибыль",
2_000_000 + index * 25_000,
80_000 + index * 500,
),
)
expected_keys = set()
for report_year in report_years:
years_before_current = current_year - report_year
for (
form_code,
line_code,
line_name,
current_period_end,
annual_change,
) in expected:
period_end = current_period_end - annual_change * years_before_current
expected_keys.add((form_code, line_code, report_year))
defaults = {
"line_name": line_name,
"period_start": period_end - 100_000,
"period_start": period_end - annual_change,
"period_end": period_end,
},
)
FinancialReportLine.objects.update_or_create(
report=legacy_report,
form_code=form_code,
line_code=line_code,
year=report_year,
defaults={
"line_name": line_name,
"period_start": period_end - 100_000,
"period_end": period_end,
},
)
}
OrganizationSourceFinancialLine.objects.update_or_create(
source_record=record,
form_code=form_code,
line_code=line_code,
year=report_year,
defaults=defaults,
)
FinancialReportLine.objects.update_or_create(
report=legacy_report,
form_code=form_code,
line_code=line_code,
year=report_year,
defaults=defaults,
)
lines = OrganizationSourceFinancialLine.objects.filter(source_record=record)
for line in lines:
key = (line.form_code, line.line_code, line.year)
if key not in expected_keys:
line.delete()
legacy_report.lines.exclude(year=report_year).delete()
for line in legacy_report.lines.all():
key = (line.form_code, line.line_code, line.year)
if key not in expected_keys:
line.delete()
@staticmethod
def _refresh_extension_counters(*, organization) -> None: