- 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>
16 lines
547 B
Python
16 lines
547 B
Python
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()
|