fix: mirror current-year test finance lines
All checks were successful
CI/CD Pipeline / Quality Gate (push) Successful in 33s
CI/CD Pipeline / Build and Push Images (push) Successful in 20s
CI/CD Pipeline / Internal Notify (push) Successful in 0s
CI/CD Pipeline / Deploy Dev via Compose (push) Successful in 23s

This commit is contained in:
2026-08-09 13:10:57 +02:00
parent 2d990ccf6a
commit 5618155503
2 changed files with 47 additions and 4 deletions

View File

@@ -10,6 +10,7 @@ from uuid import UUID, uuid5
from apps.parsers.models import (
FinancialReport,
FinancialReportLine,
GenericParserRecord,
IndustrialCertificateRecord,
IndustrialProductRecord,
@@ -130,7 +131,11 @@ class TestCompanyDatasetService:
record.legacy_pk = str(legacy_record.pk)
record.save(update_fields=["legacy_model", "legacy_pk", "updated_at"])
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(
extension__organization=organization,
@@ -423,6 +428,7 @@ class TestCompanyDatasetService:
@classmethod
def _record_defaults(cls, *, source: str, index: int, organization):
report_year = timezone.localdate().year
common = {
"inn": organization.inn,
"ogrn": organization.ogrn,
@@ -433,8 +439,11 @@ class TestCompanyDatasetService:
url = f"https://example.test/{source}/{index}"
values = {
ParserLoadLog.Source.FNS_REPORTS: {
"title": f"Бухгалтерская отчетность за 2025 год — {organization.name}",
"record_date": "2025",
"title": (
f"Бухгалтерская отчетность за {report_year} год — "
f"{organization.name}"
),
"record_date": str(report_year),
"status": "processed",
"payload": {
**common,
@@ -660,7 +669,7 @@ class TestCompanyDatasetService:
}
@staticmethod
def _refresh_financial_lines(*, record, index: int) -> None:
def _refresh_financial_lines(*, record, legacy_report, index: int) -> None:
report_year = timezone.localdate().year
expected = {
("1", "1600", "Баланс (актив)", 10_000_000 + index * 100_000),
@@ -682,11 +691,23 @@ class TestCompanyDatasetService:
"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)
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()
@staticmethod
def _refresh_extension_counters(*, organization) -> None: