## Store Profiles System
- Add ProfileRegistry for CUI-based profile lookup
- Add BaseStoreProfile with generic extraction patterns
- Implement hot-reload via POST /api/data-entry/ocr/profiles/reload
## 12 Store Profiles
- LIDL: Multi-rate TVA (A, B, C, D codes)
- OMV, SOCAR: B2B with client CUI, YYYY.MM.DD dates
- BRICK, DEDEMAN: Standard TVA, e-factura support
- KINETERRA, BEST PRINT: Non-VAT payers (returns [])
- STEPOUT MARKET: TVA 5% (books/reduced rate)
- UNLIMITED KEYS: NUMERAR payment detection
- GAMA INK, ELECTROBERING, PICTUS VELUM: Standard TVA
## Flexible TVA Patterns
- All patterns use (\d{1,2})% to accept any rate
- Supports historical (19%, 9%, 5%) and current (21%, 11%)
## Payment Methods Fix
- Fixed base.py to support multiple payments of same type
- Changed deduplication from method-only to (method, amount) tuple
- Returns separate entries for split payments
## Tools
- Add generate_store_profile.py for automatic profile generation
- Analyzes PDFs via OCR API and detects patterns
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
102 lines
3.2 KiB
Python
102 lines
3.2 KiB
Python
"""
|
|
BRICK (Five-Holding) store profile for OCR extraction.
|
|
|
|
Five-Holding S.A. operates BRICK stores with standard receipt format.
|
|
"""
|
|
|
|
import re
|
|
from decimal import Decimal, InvalidOperation
|
|
from typing import List, Dict, Any
|
|
|
|
from .base import BaseStoreProfile
|
|
from . import ProfileRegistry
|
|
|
|
|
|
@ProfileRegistry.register
|
|
class BrickProfile(BaseStoreProfile):
|
|
"""
|
|
FIVE-HOLDING S.A. (BRICK) - standard TVA format.
|
|
|
|
Key characteristics:
|
|
- Standard TVA format
|
|
- Single TVA rate typically
|
|
- No client CUI on receipts
|
|
"""
|
|
|
|
CUI_LIST = ["10562600"]
|
|
NAME_PATTERNS = ["BRICK", "FIVE-HOLDING", "FIVE HOLDING", "BR1CK"] # OCR variants
|
|
STORE_NAME = "FIVE-HOLDING S.A."
|
|
|
|
# Standard TVA patterns (flexible - accepts any rate)
|
|
TVA_PATTERNS = [
|
|
# "TVA A: XX% = YY,YY" or "TVA-A XX% YY,YY"
|
|
r'TVA\s*[-:]?\s*([A-D])\s*:?\s*(\d{1,2})\s*%\s*[=:]?\s*([\d.,]+)',
|
|
# "A - XX,XX% = YY,YY"
|
|
r'([A-D])\s*[-:]\s*(\d{1,2})[.,]?\d{0,2}\s*%\s*[=:]?\s*([\d.,]+)',
|
|
# Simple: "TVA XX% YY,YY"
|
|
r'TVA\s+(\d{1,2})\s*%\s*([\d.,]+)',
|
|
]
|
|
|
|
def extract_tva_entries(self, text: str) -> List[dict]:
|
|
"""
|
|
Extract BRICK-specific TVA entries.
|
|
|
|
Args:
|
|
text: Raw OCR text from receipt
|
|
|
|
Returns:
|
|
List of TVA entries with code, percent, and amount
|
|
"""
|
|
entries = []
|
|
seen = set()
|
|
|
|
# Try coded patterns first
|
|
for pattern in self.TVA_PATTERNS[:2]:
|
|
for match in re.finditer(pattern, text, re.IGNORECASE):
|
|
try:
|
|
code = match.group(1).upper()
|
|
percent = int(match.group(2))
|
|
amount = self._parse_decimal(match.group(3))
|
|
|
|
if amount and amount > 0:
|
|
entry_key = (code, percent)
|
|
if entry_key not in seen:
|
|
entries.append({
|
|
'code': code,
|
|
'percent': percent,
|
|
'amount': amount
|
|
})
|
|
seen.add(entry_key)
|
|
except (ValueError, InvalidOperation, IndexError):
|
|
continue
|
|
|
|
# Fallback to simple format
|
|
if not entries:
|
|
simple_pattern = self.TVA_PATTERNS[2]
|
|
for match in re.finditer(simple_pattern, text, re.IGNORECASE):
|
|
try:
|
|
percent = int(match.group(1))
|
|
amount = self._parse_decimal(match.group(2))
|
|
|
|
if amount and amount > 0:
|
|
entries.append({
|
|
'code': 'A',
|
|
'percent': percent,
|
|
'amount': amount
|
|
})
|
|
break
|
|
except (ValueError, InvalidOperation):
|
|
continue
|
|
|
|
return entries
|
|
|
|
def get_validation_hints(self) -> Dict[str, Any]:
|
|
"""Return BRICK-specific validation hints."""
|
|
return {
|
|
"has_multi_rate_tva": False,
|
|
"card_equals_total": False,
|
|
"has_client_cui": False,
|
|
"has_efactura": False,
|
|
"is_non_vat_payer": False,
|
|
}
|