feat(organizations): generate complete test statements
All checks were successful
CI/CD Pipeline / Quality Gate (push) Successful in 59s
CI/CD Pipeline / Build and Push Images (push) Successful in 17s
CI/CD Pipeline / Internal Notify (push) Successful in 1s
CI/CD Pipeline / Deploy Dev via Compose (push) Successful in 29s

This commit is contained in:
2026-08-10 14:25:43 +02:00
parent 2a1f29983e
commit d079c74ecf
2 changed files with 407 additions and 46 deletions

View File

@@ -25,7 +25,10 @@ from organizations.models import (
SourceGroup,
)
from organizations.test_companies import (
TEST_BALANCE_LINE_NAMES,
TEST_FINANCIAL_HISTORY_YEARS,
TEST_FINANCIAL_LINES_PER_YEAR,
TEST_PROFIT_LOSS_LINE_NAMES,
TEST_RECORD_PREFIX,
)
@@ -92,7 +95,7 @@ class TestCompaniesCommandsTest(TestCase):
OrganizationSourceFinancialLine.objects.filter(
source_record__extension__organization__in=companies
).count(),
20 * 4 * TEST_FINANCIAL_HISTORY_YEARS,
20 * TEST_FINANCIAL_LINES_PER_YEAR * TEST_FINANCIAL_HISTORY_YEARS,
)
current_year = timezone.localdate().year
expected_financial_years = set(
@@ -124,7 +127,7 @@ class TestCompaniesCommandsTest(TestCase):
)
self.assertEqual(
FinancialReportLine.objects.count(),
20 * 4 * TEST_FINANCIAL_HISTORY_YEARS,
20 * TEST_FINANCIAL_LINES_PER_YEAR * TEST_FINANCIAL_HISTORY_YEARS,
)
self.assertEqual(
set(FinancialReportLine.objects.values_list("year", flat=True)),
@@ -250,14 +253,10 @@ class TestCompaniesCommandsTest(TestCase):
self.assertEqual(len(reports), 20)
self.assertEqual(
sum(len(report["lines"]) for report in reports),
20 * 4 * TEST_FINANCIAL_HISTORY_YEARS,
20 * TEST_FINANCIAL_LINES_PER_YEAR * TEST_FINANCIAL_HISTORY_YEARS,
)
self.assertEqual(
{
line["year"]
for report in reports
for line in report["lines"]
},
{line["year"] for report in reports for line in report["lines"]},
set(
range(
timezone.localdate().year - TEST_FINANCIAL_HISTORY_YEARS + 1,
@@ -266,6 +265,138 @@ class TestCompaniesCommandsTest(TestCase):
),
)
def test_financial_statements_are_complete_balanced_and_periodic(self):
call_command("create_test_companies", stdout=StringIO())
company = Organization.objects.get(name="Тестовая компания 1")
record = OrganizationSourceRecord.objects.get(
extension__organization=company,
source=ParserLoadLog.Source.FNS_REPORTS,
)
lines = list(
OrganizationSourceFinancialLine.objects.filter(
source_record=record
).order_by("year", "form_code", "line_code")
)
self.assertEqual(
len(lines),
TEST_FINANCIAL_LINES_PER_YEAR * TEST_FINANCIAL_HISTORY_YEARS,
)
self.assertTrue(
all(
line.period_start is not None and line.period_end is not None
for line in lines
)
)
lines_by_year = {}
for line in lines:
lines_by_year.setdefault(line.year, {})[
(line.form_code, line.line_code)
] = line
expected_codes = {
*(("1", code) for code in TEST_BALANCE_LINE_NAMES),
*(("2", code) for code in TEST_PROFIT_LOSS_LINE_NAMES),
}
ordered_years = sorted(lines_by_year)
for year in ordered_years:
year_lines = lines_by_year[year]
self.assertEqual(set(year_lines), expected_codes)
values = {key: line.period_end for key, line in year_lines.items()}
self.assertEqual(
values[("1", "1100")],
sum(
values[("1", code)]
for code in (
"1110",
"1120",
"1130",
"1140",
"1150",
"1160",
"1170",
"1180",
"1190",
)
),
)
self.assertEqual(
values[("1", "1200")],
sum(
values[("1", code)]
for code in ("1210", "1220", "1230", "1240", "1250", "1260")
),
)
self.assertEqual(
values[("1", "1600")],
values[("1", "1100")] + values[("1", "1200")],
)
self.assertEqual(
values[("1", "1300")],
sum(
values[("1", code)]
for code in ("1310", "1320", "1340", "1350", "1360", "1370")
),
)
self.assertEqual(
values[("1", "1400")],
sum(values[("1", code)] for code in ("1410", "1420", "1430", "1450")),
)
self.assertEqual(
values[("1", "1500")],
sum(
values[("1", code)]
for code in ("1510", "1520", "1530", "1540", "1550")
),
)
self.assertEqual(values[("1", "1600")], values[("1", "1700")])
self.assertEqual(
values[("2", "2100")],
values[("2", "2110")] - values[("2", "2120")],
)
self.assertEqual(
values[("2", "2200")],
values[("2", "2100")] - values[("2", "2210")] - values[("2", "2220")],
)
self.assertEqual(
values[("2", "2300")],
values[("2", "2200")]
+ values[("2", "2310")]
+ values[("2", "2320")]
- values[("2", "2330")]
+ values[("2", "2340")]
- values[("2", "2350")],
)
self.assertEqual(
values[("2", "2410")],
values[("2", "2411")] + values[("2", "2412")],
)
self.assertEqual(
values[("2", "2400")],
values[("2", "2300")] - values[("2", "2410")] - values[("2", "2460")],
)
self.assertEqual(
values[("2", "2500")],
values[("2", "2400")]
+ values[("2", "2510")]
+ values[("2", "2520")]
- values[("2", "2530")],
)
for previous_year, current_year in zip(
ordered_years,
ordered_years[1:],
strict=False,
):
for key, current_line in lines_by_year[current_year].items():
self.assertEqual(
current_line.period_start,
lines_by_year[previous_year][key].period_end,
)
def test_delete_removes_only_the_fixed_twenty_companies(self):
untouched = Organization.objects.create(
name="Тестовая компания 99",