From 2ec1fc0f1916dfc5220ccee161038ddcd723d7d5 Mon Sep 17 00:00:00 2001 From: Claude Agent Date: Thu, 2 Apr 2026 14:33:14 +0000 Subject: [PATCH] =?UTF-8?q?fix(anaf):=20sanitize=20OCR-like=20typos=20in?= =?UTF-8?q?=20CUI=20(O=E2=86=920,=20I=E2=86=921,=20L=E2=86=921)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- api/app/services/anaf_service.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/api/app/services/anaf_service.py b/api/app/services/anaf_service.py index 993bc08..5bc24c3 100644 --- a/api/app/services/anaf_service.py +++ b/api/app/services/anaf_service.py @@ -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: