fix: resolve parser organizations from directory only
Some checks failed
CI/CD Pipeline / Quality Gate (push) Failing after 32s
CI/CD Pipeline / Build and Push Images (push) Has been skipped
CI/CD Pipeline / Internal Notify (push) Successful in 0s
CI/CD Pipeline / Deploy Dev via Compose (push) Has been skipped

This commit is contained in:
2026-06-07 16:28:57 +02:00
parent 6ba8fa8d88
commit 802257a757
19 changed files with 184 additions and 83 deletions

View File

@@ -85,32 +85,34 @@ class OrganizationDirectoryResolver:
@classmethod
def resolve(cls, identity: OrganizationIdentity) -> OrganizationResolveResult: # noqa: C901
directory = cls._directory_queryset()
if identity.rn:
organization = cls._single(Organization.objects.filter(rn=identity.rn))
organization = cls._single(directory.filter(rn=identity.rn))
if organization is not None:
return OrganizationResolveResult("matched", organization)
if identity.okpo:
result = cls._resolve_unique(Organization.objects.filter(okpo=identity.okpo))
result = cls._resolve_unique(directory.filter(okpo=identity.okpo))
if result.status != "unmatched":
return result
if identity.inn and identity.kpp:
result = cls._resolve_unique(
Organization.objects.filter(inn=identity.inn, kpp=identity.kpp),
directory.filter(inn=identity.inn, kpp=identity.kpp),
)
if result.status != "unmatched":
return result
if identity.ogrn and identity.kpp:
result = cls._resolve_unique(
Organization.objects.filter(ogrn=identity.ogrn, kpp=identity.kpp),
directory.filter(ogrn=identity.ogrn, kpp=identity.kpp),
)
if result.status != "unmatched":
return result
if identity.ogrip:
result = cls._resolve_unique(Organization.objects.filter(ogrip=identity.ogrip))
result = cls._resolve_unique(directory.filter(ogrip=identity.ogrip))
if result.status != "unmatched":
return result
@@ -118,24 +120,28 @@ class OrganizationDirectoryResolver:
return cls._resolve_by_inn_ogrn(identity.inn, identity.ogrn)
if identity.inn:
result = cls._resolve_unique(Organization.objects.filter(inn=identity.inn))
result = cls._resolve_unique(directory.filter(inn=identity.inn))
if result.status != "unmatched":
return result
if identity.ogrn:
result = cls._resolve_unique(Organization.objects.filter(ogrn=identity.ogrn))
result = cls._resolve_unique(directory.filter(ogrn=identity.ogrn))
if result.status != "unmatched":
return result
return OrganizationResolveResult("unmatched")
@staticmethod
def _directory_queryset():
return Organization.objects.filter(directory_imported_at__isnull=False)
@classmethod
def _resolve_by_inn_ogrn(
cls,
inn: str,
ogrn: str,
) -> OrganizationResolveResult:
queryset = Organization.objects.filter(inn=inn, ogrn=ogrn)
queryset = cls._directory_queryset().filter(inn=inn, ogrn=ogrn)
result = cls._resolve_unique(queryset)
if result.status != "ambiguous":
return result