fix: search parser records by registry organization
All checks were successful
CI/CD Pipeline / Quality Gate (push) Successful in 32s
CI/CD Pipeline / Build and Push Images (push) Successful in 19s
CI/CD Pipeline / Internal Notify (push) Successful in 1s
CI/CD Pipeline / Deploy Dev in Dokploy (push) Successful in 2s

This commit is contained in:
2026-06-01 11:42:35 +02:00
parent e81bf65289
commit 2368bb7fb0
2 changed files with 259 additions and 31 deletions

View File

@@ -769,6 +769,166 @@ class ParsersViewSetTest(APITestCase):
self.assertEqual(unified_response.data["data"][0]["id"], report.id)
self.assertEqual(unified_response.data["data"][0]["title"], report.file_name)
def test_financial_reports_list_searches_registry_organization_name(self):
organization = RegisterOrganizationFactory(
pn_name="тест-организация-фнс",
mn_ogrn=1111111111111,
mn_inn=1111111111,
)
matching_report = FinancialReport.objects.create(
external_id="fns-test-organization",
ogrn=str(organization.mn_ogrn),
registry_organization=organization,
file_name=f"fin_fns-test-organization_{organization.mn_ogrn}.xlsx",
file_hash=fake.sha256(raw_output=False),
load_batch=1,
status=FinancialReport.Status.SUCCESS,
source=FinancialReport.SourceType.API,
)
FinancialReport.objects.create(
external_id="fns-other-organization",
ogrn="1027700000002",
file_name="fin_fns-other-organization_1027700000002.xlsx",
file_hash=fake.sha256(raw_output=False),
load_batch=1,
status=FinancialReport.Status.SUCCESS,
source=FinancialReport.SourceType.API,
)
self.client.force_authenticate(self.user)
response = self.client.get(
reverse("api_v1:fns:fns-reports-list"),
{"search": "тест-организация", "page_size": 20},
)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(
[item["id"] for item in response.data["data"]],
[matching_report.id],
)
def test_native_source_lists_search_registry_organization_identity_fields(self):
organization = RegisterOrganizationFactory(
pn_name="тест-организация-источники",
mn_ogrn=1111111111111,
mn_inn=1111111111,
mn_okpo="11111111",
)
certificate = IndustrialCertificateRecordFactory(
registry_organization=organization,
inn="9000000001",
ogrn="1090000000001",
)
manufacturer = ManufacturerRecordFactory(
registry_organization=organization,
inn="9000000002",
ogrn="1090000000002",
)
product = IndustrialProductRecordFactory(
registry_organization=organization,
inn="9000000003",
ogrn="1090000000003",
)
inspection = InspectionRecordFactory(
registry_organization=organization,
inn="9000000004",
ogrn="1090000000004",
)
procurement = ProcurementRecord.objects.create(
load_batch=1,
purchase_number="TST-PURCHASE-IDENTITY",
purchase_name="Поставка тестовой продукции",
customer_inn="9000000005",
customer_kpp="900000001",
customer_ogrn="1090000000005",
customer_name='ООО "Не тестовая организация"',
max_price="1000.00",
status="active",
law_type="44-FZ",
href="https://zakupki.example.test/purchase",
region_code="77",
registry_organization=organization,
)
financial_report = FinancialReport.objects.create(
external_id="fns-native-source-identity",
ogrn="1090000000006",
registry_organization=organization,
file_name="fin_native_source_identity_1090000000006.xlsx",
file_hash=fake.sha256(raw_output=False),
load_batch=1,
status=FinancialReport.Status.SUCCESS,
source=FinancialReport.SourceType.API,
)
self.client.force_authenticate(self.user)
cases = [
(reverse("api_v1:minpromtorg:certificates-list"), certificate.id),
(reverse("api_v1:minpromtorg:manufacturers-list"), manufacturer.id),
(reverse("api_v1:minpromtorg:industrial-products-list"), product.id),
(reverse("api_v1:proverki:inspections-list"), inspection.id),
(reverse("api_v1:zakupki:procurements-list"), procurement.id),
(reverse("api_v1:fns:fns-reports-list"), financial_report.id),
]
for url, expected_id in cases:
with self.subTest(url=url):
response = self.client.get(
url,
{"search": organization.mn_okpo, "page_size": 20},
)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(
[item["id"] for item in response.data["data"]],
[expected_id],
)
def test_generic_source_results_search_registry_organization_identity_fields(self):
organization = RegisterOrganizationFactory(
pn_name="тест-организация-generic",
mn_ogrn=2222222222222,
mn_inn=2222222222,
mn_okpo="22222222",
)
matching_record = GenericParserRecord.objects.create(
load_batch=1,
source=ParserLoadLog.Source.FAS_GOZ,
external_id="goz-linked-organization",
inn="9000000010",
ogrn="1090000000010",
organisation_name='ООО "Другое имя"',
title="Уклонение от ГОЗ",
registry_organization=organization,
)
GenericParserRecord.objects.create(
load_batch=1,
source=ParserLoadLog.Source.FAS_GOZ,
external_id="goz-unlinked-organization",
inn="9000000011",
ogrn="1090000000011",
organisation_name='ООО "Не подходит"',
title="Уклонение от ГОЗ",
)
self.client.force_authenticate(self.user)
for search_query in (
organization.pn_name,
str(organization.mn_inn),
str(organization.mn_ogrn),
organization.mn_okpo,
):
with self.subTest(search_query=search_query):
response = self.client.get(
"/api/v1/fas/goz/",
{"search": search_query, "page_size": 20},
)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(
[item["id"] for item in response.data["data"]],
[matching_record.id],
)
def test_fns_financial_results_searches_and_orders_by_registry_organization(self):
alpha_org = RegisterOrganizationFactory(
pn_name='alpha "ФНС"',