feat: Parser-Basis, Bank-Erkennung, Saldo-/Duplikat-Pruefung

- ParsedTransaction und ParsedStatement Datenklassen
- parse_german_amount(): German format number parsing (1.234,56 -> Decimal)
- parse_german_date(): DD.MM.YYYY date parsing with optional year
- detect_bank(): Recognize VR/HVB/DKB from text markers
- balance_difference(): Validate statement balance consistency
- dedup_hash(): SHA256-based transaction deduplication

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-17 17:30:10 +02:00
parent 877cba4964
commit d91bb2e331
5 changed files with 121 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
import hashlib
from datetime import date
from decimal import Decimal
from app.parsers.base import ParsedStatement
def balance_difference(p: ParsedStatement) -> Decimal:
total = sum((t.amount for t in p.transactions), Decimal("0"))
return (p.opening_balance + total - p.closing_balance).copy_abs()
def dedup_hash(account_id: int, booking_date: date, amount: Decimal, purpose: str) -> str:
raw = f"{account_id}|{booking_date.isoformat()}|{amount:.2f}|{' '.join(purpose.split())}"
return hashlib.sha256(raw.encode()).hexdigest()