fix(parsers): disambiguate ROPK organizations by OKPO
All checks were successful
All checks were successful
This commit is contained in:
@@ -159,7 +159,7 @@ def _resolve_organization(
|
||||
return None, "missing_required_value"
|
||||
|
||||
if inn and ogrn:
|
||||
candidates = list(directory.filter(inn=inn, ogrn=ogrn)[:2])
|
||||
candidates = list(directory.filter(inn=inn, ogrn=ogrn, okpo=okpo)[:2])
|
||||
if len(candidates) > 1:
|
||||
return None, "organization_ambiguous"
|
||||
if not candidates:
|
||||
@@ -172,8 +172,6 @@ def _resolve_organization(
|
||||
else "organization_not_found"
|
||||
)
|
||||
organization = candidates[0]
|
||||
if organization.okpo != okpo:
|
||||
return None, "identifier_mismatch"
|
||||
else:
|
||||
candidates = list(directory.filter(okpo=okpo)[:2])
|
||||
if len(candidates) > 1:
|
||||
|
||||
@@ -131,6 +131,50 @@ class RopkSanctionsImportTest(TestCase):
|
||||
self.assertEqual(record.extension.organization.inn, "0012345678")
|
||||
self.assertEqual(record.extension.organization.ogrn, "1027700132195")
|
||||
|
||||
def test_import_uses_okpo_to_disambiguate_duplicate_inn_and_ogrn(self):
|
||||
Organization.objects.create(
|
||||
name="Филиал с другим ОКПО",
|
||||
inn=self.organization.inn,
|
||||
ogrn=self.organization.ogrn,
|
||||
okpo="00999999",
|
||||
opk_registry_membership=True,
|
||||
directory_imported_at=timezone.now(),
|
||||
)
|
||||
|
||||
_, result = import_ropk_sanctions(
|
||||
handle=_workbook([_row("pair-duplicate")]),
|
||||
original_name="sanctions.xlsx",
|
||||
load_batch=22,
|
||||
uploaded_by_id=None,
|
||||
)
|
||||
|
||||
self.assertEqual(result.published, 1)
|
||||
self.assertEqual(result.quarantined, 0)
|
||||
record = OrganizationSourceRecord.objects.get()
|
||||
self.assertEqual(record.extension.organization_id, self.organization.uid)
|
||||
|
||||
def test_import_quarantines_duplicate_inn_ogrn_and_okpo(self):
|
||||
Organization.objects.create(
|
||||
name="Полный дубль идентификаторов",
|
||||
inn=self.organization.inn,
|
||||
ogrn=self.organization.ogrn,
|
||||
okpo=self.organization.okpo,
|
||||
opk_registry_membership=True,
|
||||
directory_imported_at=timezone.now(),
|
||||
)
|
||||
|
||||
_, result = import_ropk_sanctions(
|
||||
handle=_workbook([_row("triple-duplicate")]),
|
||||
original_name="sanctions.xlsx",
|
||||
load_batch=23,
|
||||
uploaded_by_id=None,
|
||||
)
|
||||
|
||||
self.assertEqual(result.published, 0)
|
||||
self.assertEqual(result.quarantined, 1)
|
||||
self.assertEqual(result.reasons, {"organization_ambiguous": 1})
|
||||
self.assertFalse(OrganizationSourceRecord.objects.exists())
|
||||
|
||||
def test_import_preserves_full_fourteen_digit_okpo(self):
|
||||
self.organization.okpo = "00123456789012"
|
||||
self.organization.save(update_fields=["okpo"])
|
||||
|
||||
Reference in New Issue
Block a user