feat: use authoritative organization directory
This commit is contained in:
@@ -5,9 +5,12 @@
|
||||
from apps.parsers.clients.fns.parser import FNSExcelParser, FNSParserError
|
||||
from apps.parsers.clients.fns.schemas import ParsedReport, ReportLine
|
||||
from apps.parsers.models import FinancialReport
|
||||
from apps.parsers.services import FNSReportService
|
||||
from apps.registers.models import Organization
|
||||
from apps.parsers.services import (
|
||||
FNSReportOrganizationResolutionSkipped,
|
||||
FNSReportService,
|
||||
)
|
||||
from django.test import TestCase
|
||||
from organizations.models import Organization
|
||||
|
||||
from tests.utils.fixtures import fake
|
||||
|
||||
@@ -30,11 +33,11 @@ def _form_code() -> str:
|
||||
|
||||
def _create_registry_organization(*, inn: str, ogrn: str) -> Organization:
|
||||
return Organization.objects.create(
|
||||
pn_name=fake.company(),
|
||||
mn_ogrn=int(ogrn),
|
||||
mn_inn=int(inn),
|
||||
in_kpp=int(_digits(9)),
|
||||
mn_okpo=_digits(8),
|
||||
name=fake.company(),
|
||||
ogrn=ogrn,
|
||||
inn=inn,
|
||||
kpp=_digits(9),
|
||||
okpo=_digits(8),
|
||||
)
|
||||
|
||||
|
||||
@@ -277,6 +280,7 @@ class TestFNSReportServiceIntegration(TestCase):
|
||||
"""Сохранение отчета."""
|
||||
external_id = _digits(6)
|
||||
ogrn = _digits(13)
|
||||
_create_registry_organization(inn=_digits(10), ogrn=ogrn)
|
||||
file_hash = fake.sha1(raw_output=False)
|
||||
lines_data = [
|
||||
{
|
||||
@@ -314,7 +318,7 @@ class TestFNSReportServiceIntegration(TestCase):
|
||||
self.assertEqual(report.lines.count(), 2)
|
||||
|
||||
def test_save_report_links_registry_organization_when_exists(self):
|
||||
"""Отчет ФНС должен связываться с организацией из registers по ОГРН."""
|
||||
"""Отчет ФНС должен связываться с организацией из справочника по ОГРН."""
|
||||
ogrn = _digits(13)
|
||||
organization = _create_registry_organization(inn=_digits(10), ogrn=ogrn)
|
||||
external_id = _digits(6)
|
||||
@@ -331,12 +335,32 @@ class TestFNSReportServiceIntegration(TestCase):
|
||||
|
||||
self.assertEqual(report.registry_organization_id, organization.id)
|
||||
|
||||
def test_save_report_raises_skipped_when_organization_is_ambiguous(self):
|
||||
ogrn = _digits(13)
|
||||
_create_registry_organization(inn=_digits(10), ogrn=ogrn)
|
||||
_create_registry_organization(inn=_digits(10), ogrn=ogrn)
|
||||
|
||||
with self.assertRaises(FNSReportOrganizationResolutionSkipped) as exc:
|
||||
FNSReportService.save_report(
|
||||
external_id=_digits(6),
|
||||
ogrn=ogrn,
|
||||
file_name=f"fin_{_digits(6)}_{ogrn}.xlsx",
|
||||
file_hash=fake.sha1(raw_output=False),
|
||||
source=FinancialReport.SourceType.API,
|
||||
batch_id=1,
|
||||
lines_data=[],
|
||||
)
|
||||
|
||||
self.assertEqual(exc.exception.reason, "ambiguous")
|
||||
|
||||
def test_exists_by_hash(self):
|
||||
"""Проверка существования по хешу."""
|
||||
unique_hash = fake.sha1(raw_output=False)
|
||||
ogrn = _digits(13)
|
||||
_create_registry_organization(inn=_digits(10), ogrn=ogrn)
|
||||
FNSReportService.save_report(
|
||||
external_id=_digits(6),
|
||||
ogrn=_digits(13),
|
||||
ogrn=ogrn,
|
||||
file_name=fake.file_name(extension="xlsx"),
|
||||
file_hash=unique_hash,
|
||||
source=FinancialReport.SourceType.API,
|
||||
@@ -350,6 +374,7 @@ class TestFNSReportServiceIntegration(TestCase):
|
||||
def test_find_by_ogrn(self):
|
||||
"""Поиск по ОГРН."""
|
||||
ogrn = _digits(13)
|
||||
_create_registry_organization(inn=_digits(10), ogrn=ogrn)
|
||||
FNSReportService.save_report(
|
||||
external_id=_digits(6),
|
||||
ogrn=ogrn,
|
||||
|
||||
Reference in New Issue
Block a user