fix: mirror current-year test finance lines
This commit is contained in:
@@ -10,6 +10,7 @@ from uuid import UUID, uuid5
|
|||||||
|
|
||||||
from apps.parsers.models import (
|
from apps.parsers.models import (
|
||||||
FinancialReport,
|
FinancialReport,
|
||||||
|
FinancialReportLine,
|
||||||
GenericParserRecord,
|
GenericParserRecord,
|
||||||
IndustrialCertificateRecord,
|
IndustrialCertificateRecord,
|
||||||
IndustrialProductRecord,
|
IndustrialProductRecord,
|
||||||
@@ -130,7 +131,11 @@ class TestCompanyDatasetService:
|
|||||||
record.legacy_pk = str(legacy_record.pk)
|
record.legacy_pk = str(legacy_record.pk)
|
||||||
record.save(update_fields=["legacy_model", "legacy_pk", "updated_at"])
|
record.save(update_fields=["legacy_model", "legacy_pk", "updated_at"])
|
||||||
if source == ParserLoadLog.Source.FNS_REPORTS:
|
if source == ParserLoadLog.Source.FNS_REPORTS:
|
||||||
cls._refresh_financial_lines(record=record, index=index)
|
cls._refresh_financial_lines(
|
||||||
|
record=record,
|
||||||
|
legacy_report=legacy_record,
|
||||||
|
index=index,
|
||||||
|
)
|
||||||
|
|
||||||
OrganizationSourceRecord.objects.filter(
|
OrganizationSourceRecord.objects.filter(
|
||||||
extension__organization=organization,
|
extension__organization=organization,
|
||||||
@@ -423,6 +428,7 @@ class TestCompanyDatasetService:
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _record_defaults(cls, *, source: str, index: int, organization):
|
def _record_defaults(cls, *, source: str, index: int, organization):
|
||||||
|
report_year = timezone.localdate().year
|
||||||
common = {
|
common = {
|
||||||
"inn": organization.inn,
|
"inn": organization.inn,
|
||||||
"ogrn": organization.ogrn,
|
"ogrn": organization.ogrn,
|
||||||
@@ -433,8 +439,11 @@ class TestCompanyDatasetService:
|
|||||||
url = f"https://example.test/{source}/{index}"
|
url = f"https://example.test/{source}/{index}"
|
||||||
values = {
|
values = {
|
||||||
ParserLoadLog.Source.FNS_REPORTS: {
|
ParserLoadLog.Source.FNS_REPORTS: {
|
||||||
"title": f"Бухгалтерская отчетность за 2025 год — {organization.name}",
|
"title": (
|
||||||
"record_date": "2025",
|
f"Бухгалтерская отчетность за {report_year} год — "
|
||||||
|
f"{organization.name}"
|
||||||
|
),
|
||||||
|
"record_date": str(report_year),
|
||||||
"status": "processed",
|
"status": "processed",
|
||||||
"payload": {
|
"payload": {
|
||||||
**common,
|
**common,
|
||||||
@@ -660,7 +669,7 @@ class TestCompanyDatasetService:
|
|||||||
}
|
}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _refresh_financial_lines(*, record, index: int) -> None:
|
def _refresh_financial_lines(*, record, legacy_report, index: int) -> None:
|
||||||
report_year = timezone.localdate().year
|
report_year = timezone.localdate().year
|
||||||
expected = {
|
expected = {
|
||||||
("1", "1600", "Баланс (актив)", 10_000_000 + index * 100_000),
|
("1", "1600", "Баланс (актив)", 10_000_000 + index * 100_000),
|
||||||
@@ -682,11 +691,23 @@ class TestCompanyDatasetService:
|
|||||||
"period_end": period_end,
|
"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,
|
||||||
|
},
|
||||||
|
)
|
||||||
lines = OrganizationSourceFinancialLine.objects.filter(source_record=record)
|
lines = OrganizationSourceFinancialLine.objects.filter(source_record=record)
|
||||||
for line in lines:
|
for line in lines:
|
||||||
key = (line.form_code, line.line_code, line.year)
|
key = (line.form_code, line.line_code, line.year)
|
||||||
if key not in expected_keys:
|
if key not in expected_keys:
|
||||||
line.delete()
|
line.delete()
|
||||||
|
legacy_report.lines.exclude(year=report_year).delete()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _refresh_extension_counters(*, organization) -> None:
|
def _refresh_extension_counters(*, organization) -> None:
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ from io import StringIO
|
|||||||
from apps.exchange.state_corp_services import StateCorpExchangeService
|
from apps.exchange.state_corp_services import StateCorpExchangeService
|
||||||
from apps.parsers.models import (
|
from apps.parsers.models import (
|
||||||
FinancialReport,
|
FinancialReport,
|
||||||
|
FinancialReportLine,
|
||||||
GenericParserRecord,
|
GenericParserRecord,
|
||||||
IndustrialCertificateRecord,
|
IndustrialCertificateRecord,
|
||||||
IndustrialProductRecord,
|
IndustrialProductRecord,
|
||||||
@@ -103,6 +104,11 @@ class TestCompaniesCommandsTest(TestCase):
|
|||||||
self.assertEqual(InspectionRecord.objects.count(), 20)
|
self.assertEqual(InspectionRecord.objects.count(), 20)
|
||||||
self.assertEqual(ProcurementRecord.objects.count(), 20)
|
self.assertEqual(ProcurementRecord.objects.count(), 20)
|
||||||
self.assertEqual(FinancialReport.objects.count(), 20)
|
self.assertEqual(FinancialReport.objects.count(), 20)
|
||||||
|
self.assertEqual(FinancialReportLine.objects.count(), 20 * 4)
|
||||||
|
self.assertEqual(
|
||||||
|
set(FinancialReportLine.objects.values_list("year", flat=True)),
|
||||||
|
{timezone.localdate().year},
|
||||||
|
)
|
||||||
self.assertEqual(GenericParserRecord.objects.count(), 20 * 9)
|
self.assertEqual(GenericParserRecord.objects.count(), 20 * 9)
|
||||||
|
|
||||||
def test_create_updates_the_fixed_dataset_without_duplicates(self):
|
def test_create_updates_the_fixed_dataset_without_duplicates(self):
|
||||||
@@ -151,6 +157,12 @@ class TestCompaniesCommandsTest(TestCase):
|
|||||||
.values_list("inn", flat=True)
|
.values_list("inn", flat=True)
|
||||||
)
|
)
|
||||||
package = StateCorpExchangeService.build_package(organization_inns=company_inns)
|
package = StateCorpExchangeService.build_package(organization_inns=company_inns)
|
||||||
|
reports = StateCorpExchangeService._serialize_financial_reports(
|
||||||
|
{
|
||||||
|
organization.ogrn: organization.inn
|
||||||
|
for organization in Organization.objects.filter(inn__in=company_inns)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
package.payload_counts,
|
package.payload_counts,
|
||||||
@@ -169,6 +181,16 @@ class TestCompaniesCommandsTest(TestCase):
|
|||||||
"labor_vacancies": 20,
|
"labor_vacancies": 20,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
self.assertEqual(len(reports), 20)
|
||||||
|
self.assertEqual(sum(len(report["lines"]) for report in reports), 80)
|
||||||
|
self.assertEqual(
|
||||||
|
{
|
||||||
|
line["year"]
|
||||||
|
for report in reports
|
||||||
|
for line in report["lines"]
|
||||||
|
},
|
||||||
|
{timezone.localdate().year},
|
||||||
|
)
|
||||||
|
|
||||||
def test_delete_removes_only_the_fixed_twenty_companies(self):
|
def test_delete_removes_only_the_fixed_twenty_companies(self):
|
||||||
untouched = Organization.objects.create(
|
untouched = Organization.objects.create(
|
||||||
|
|||||||
Reference in New Issue
Block a user