fix: match prefixed contract core aliases

This commit is contained in:
Repinoid
2026-10-31 10:10:59 +03:00
parent 8481044dea
commit 9210c6e86d
+23 -3
View File
@@ -59,12 +59,27 @@ def _contract_number_identity(number):
normalized = str(number or "").upper().translate(_HOMOGLYPHS)
prefix_match = re.match(r"^(?:XXX|ХХХ)\d+[-_/](.+)$", normalized)
if not prefix_match:
return {"full": full_key, "suffix": full_key, "prefixed": False}
suffix_aliases = [full_key]
numbered_suffix = re.match(r"^(.+)_\d+$", normalized)
if numbered_suffix:
core_key = canonicalize_contract_number(numbered_suffix.group(1))
if sum(character.isdigit() for character in core_key) >= 4:
suffix_aliases.append(core_key)
return {
"full": full_key, "suffix": full_key,
"suffix_aliases": suffix_aliases, "prefixed": False,
}
suffix_key = canonicalize_contract_number(prefix_match.group(1))
digit_count = sum(character.isdigit() for character in suffix_key)
if digit_count < 4:
return {"full": full_key, "suffix": full_key, "prefixed": True}
return {"full": full_key, "suffix": suffix_key, "prefixed": True}
return {
"full": full_key, "suffix": full_key,
"suffix_aliases": [full_key], "prefixed": True,
}
return {
"full": full_key, "suffix": suffix_key,
"suffix_aliases": [suffix_key], "prefixed": True,
}
def canonicalize_counterparty(name, inn):
@@ -112,6 +127,11 @@ def _shared_contract_match(left_keys, right_keys):
for right_key, right in right_keys.items():
if left_key == right_key:
return left_key, left, right
if left.get("prefixed") and not right.get("prefixed"):
same_suffix = left.get("suffix") in right.get("suffix_aliases", [])
elif right.get("prefixed") and not left.get("prefixed"):
same_suffix = right.get("suffix") in left.get("suffix_aliases", [])
else:
same_suffix = left.get("suffix") == right.get("suffix")
if same_suffix and (left.get("prefixed") or right.get("prefixed")):
if left.get("prefixed") and right.get("prefixed"):