fix(anaf): sanitize OCR-like typos in CUI (O→0, I→1, L→1)
GoMag order #4815967771 had CUI "49033O51" (letter O instead of zero). validate_cui rejected it so ANAF badge showed "?". strip_ro_prefix now translates common letter/digit confusions before validation. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -11,11 +11,14 @@ _DIACRITICS = str.maketrans('ĂăÂâÎîȘșȚțŞşŢţ', 'AAAAIISSTTSSTT')
|
||||
|
||||
|
||||
def strip_ro_prefix(cod_fiscal: str) -> str:
|
||||
"""Normalize CUI: strip whitespace, uppercase, remove 'RO' prefix."""
|
||||
"""Normalize CUI: strip whitespace, uppercase, remove 'RO' prefix, fix OCR-like typos."""
|
||||
if not cod_fiscal:
|
||||
return ""
|
||||
cleaned = cod_fiscal.strip().upper()
|
||||
return re.sub(r'^RO\s*', '', cleaned)
|
||||
cleaned = re.sub(r'^RO\s*', '', cleaned)
|
||||
# Fix common character confusions in CUI (O→0, I→1, L→1, B→8)
|
||||
cleaned = cleaned.translate(str.maketrans('OIL', '011'))
|
||||
return cleaned
|
||||
|
||||
|
||||
def validate_cui(bare_cui: str) -> bool:
|
||||
|
||||
Reference in New Issue
Block a user