fix(ocr): Improve CUI matching and vendor name extraction
- Add CUI variant matching for Romanian fiscal codes (handles "RO22891860", "RO 22891860", and "22891860" formats) in both sync_service and validation - Fix vendor name extraction to properly handle "SC." prefix (Societate Comercială) vs "SC" as staircase in addresses - Remove problematic TVA pattern that was incorrectly matching percentage values - Add docTR Plus engine option to dropdown with "(recomandat)" label 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -237,6 +237,31 @@ class SyncService:
|
||||
|
||||
return synced, errors
|
||||
|
||||
@staticmethod
|
||||
def _get_fiscal_code_variants(fiscal_code: str) -> list:
|
||||
"""
|
||||
Generate all possible variants of a Romanian fiscal code (CUI).
|
||||
Database may store: "22891860", "RO22891860", "RO 22891860"
|
||||
OCR may extract: "RO22891860" or "22891860"
|
||||
"""
|
||||
import re
|
||||
# Extract just the digits
|
||||
digits = re.sub(r'[^0-9]', '', fiscal_code)
|
||||
if not digits:
|
||||
return [fiscal_code]
|
||||
|
||||
# Generate all variants
|
||||
variants = [
|
||||
digits, # Just digits: 22891860
|
||||
f"RO{digits}", # With RO prefix: RO22891860
|
||||
f"RO {digits}", # With RO prefix and space: RO 22891860
|
||||
]
|
||||
# Also add the original if different
|
||||
if fiscal_code not in variants:
|
||||
variants.append(fiscal_code)
|
||||
|
||||
return variants
|
||||
|
||||
@staticmethod
|
||||
async def search_supplier(
|
||||
session: AsyncSession,
|
||||
@@ -251,9 +276,11 @@ class SyncService:
|
||||
"""
|
||||
# 1. Search in synced suppliers
|
||||
if fiscal_code:
|
||||
# Search all variants of the fiscal code (with/without RO, with/without space)
|
||||
variants = SyncService._get_fiscal_code_variants(fiscal_code)
|
||||
stmt = select(SyncedSupplier).where(
|
||||
SyncedSupplier.company_id == company_id,
|
||||
SyncedSupplier.fiscal_code == fiscal_code
|
||||
SyncedSupplier.fiscal_code.in_(variants)
|
||||
)
|
||||
elif name:
|
||||
stmt = select(SyncedSupplier).where(
|
||||
@@ -276,9 +303,11 @@ class SyncService:
|
||||
|
||||
# 2. Search in local suppliers
|
||||
if fiscal_code:
|
||||
# Search all variants of the fiscal code (with/without RO, with/without space)
|
||||
variants = SyncService._get_fiscal_code_variants(fiscal_code)
|
||||
stmt = select(LocalSupplier).where(
|
||||
LocalSupplier.company_id == company_id,
|
||||
LocalSupplier.fiscal_code == fiscal_code
|
||||
LocalSupplier.fiscal_code.in_(variants)
|
||||
)
|
||||
elif name:
|
||||
stmt = select(LocalSupplier).where(
|
||||
|
||||
Reference in New Issue
Block a user