fix: keep organization identity types exclusive
This commit is contained in:
@@ -27,24 +27,26 @@ def normalize_identity_fields(
|
||||
kpp_digits = digits(kpp)
|
||||
ogrn_digits = digits(ogrn)
|
||||
ogrip_digits = digits(ogrip)
|
||||
has_legal_entity_inn = len(inn_digits) == 10
|
||||
has_entrepreneur_inn = len(inn_digits) == 12
|
||||
|
||||
normalized_ogrip = ""
|
||||
if len(ogrip_digits) == VALID_OGRIP_LENGTH:
|
||||
if len(ogrip_digits) == VALID_OGRIP_LENGTH and not has_legal_entity_inn:
|
||||
normalized_ogrip = ogrip_digits
|
||||
elif len(ogrn_digits) == VALID_OGRIP_LENGTH:
|
||||
elif len(ogrn_digits) == VALID_OGRIP_LENGTH and not has_legal_entity_inn:
|
||||
normalized_ogrip = ogrn_digits
|
||||
|
||||
normalized_inn = inn_digits if len(inn_digits) in VALID_INN_LENGTHS else ""
|
||||
normalized_kpp = (
|
||||
""
|
||||
if normalized_ogrip
|
||||
if normalized_ogrip or has_entrepreneur_inn
|
||||
else kpp_digits
|
||||
if len(kpp_digits) == VALID_KPP_LENGTH
|
||||
else ""
|
||||
)
|
||||
normalized_ogrn = (
|
||||
""
|
||||
if normalized_ogrip
|
||||
if normalized_ogrip or has_entrepreneur_inn
|
||||
else ogrn_digits
|
||||
if len(ogrn_digits) == VALID_OGRN_LENGTH
|
||||
else ""
|
||||
|
||||
@@ -519,13 +519,17 @@ class OrganizationSourceIngestionService:
|
||||
if not organization.inn and safe_inn == record.inn:
|
||||
organization.inn = record.inn
|
||||
changed = True
|
||||
if not organization.kpp and record.kpp:
|
||||
has_entrepreneur_identity = bool(organization.ogrip or record.ogrip)
|
||||
has_legal_identity = bool(
|
||||
organization.kpp or organization.ogrn or record.kpp or record.ogrn
|
||||
)
|
||||
if not organization.kpp and record.kpp and not has_entrepreneur_identity:
|
||||
organization.kpp = record.kpp
|
||||
changed = True
|
||||
if not organization.ogrn and record.ogrn:
|
||||
if not organization.ogrn and record.ogrn and not has_entrepreneur_identity:
|
||||
organization.ogrn = record.ogrn
|
||||
changed = True
|
||||
if not organization.ogrip and record.ogrip:
|
||||
if not organization.ogrip and record.ogrip and not has_legal_identity:
|
||||
organization.ogrip = record.ogrip
|
||||
changed = True
|
||||
if cls._should_replace_placeholder_name(organization, record.organization_name):
|
||||
|
||||
Reference in New Issue
Block a user