fix: resolve parser organizations from directory only
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user