- FastAPI Backend mit Router (emails, invoices, auth) - PostgreSQL DB Models (Invoice, EmailLog, InvoiceDetail, User) - PyMuPDF PDF-Verarbeitung mit Steuer-Erkennung - openpyxl Excel-Export - Alembic Migration initialisiert - IMAP-Verbindung zu Strato funktioniert - Docker-Setup mit Traefik-Labels Co-Authored-By: Claude <noreply@anthropic.com>
54 lines
1.7 KiB
Python
54 lines
1.7 KiB
Python
"""PDF-Verarbeitungs-Test"""
|
|
import sys
|
|
import os
|
|
sys.path.insert(0, '/app')
|
|
|
|
import fitz
|
|
from backend.routers.invoices import extract_pdf_data, detect_tax_type, extract_amount, extract_invoice_number
|
|
|
|
def test_pdf_extraction(file_path: str):
|
|
"""Testet die Extraktion aus einer PDF-Datei"""
|
|
print(f"\n{'='*60}")
|
|
print(f"Teste: {file_path}")
|
|
print('='*60)
|
|
|
|
if not os.path.exists(file_path):
|
|
print(f"❌ Datei nicht gefunden: {file_path}")
|
|
return
|
|
|
|
# Extrahiere Daten
|
|
data = extract_pdf_data(file_path)
|
|
|
|
if "error" in data:
|
|
print(f"❌ Fehler: {data['error']}")
|
|
return
|
|
|
|
print(f"Seiten: {data.get('pages', 0)}")
|
|
print(f"Rechnungsnummer: {data.get('invoice_number') or 'Nicht gefunden'}")
|
|
print(f"Betrag: {data.get('amount')} €")
|
|
print(f"Austeller: {data.get('issuer') or 'Nicht gefunden'}")
|
|
|
|
tax_info = data.get('tax_info', {})
|
|
print(f"Steuerart: {tax_info.get('tax_type')}")
|
|
print(f"Steuersatz: {tax_info.get('tax_rate')}")
|
|
print(f"Confidence: {tax_info.get('confidence')}")
|
|
|
|
# Teste einzelne Funktionen
|
|
print(f"\n--- Einzelne Funktionen ---")
|
|
text = data.get('text', '')[:500]
|
|
print(f"Auszug aus Text:\n{text[:200]}...")
|
|
|
|
# Speichere extrahierten Text
|
|
with open(f'/tmp/test-invoices/{os.path.basename(file_path)}.txt', 'w') as f:
|
|
f.write(data.get('text', ''))
|
|
print(f"\nExtrahierter Text gespeichert in: /tmp/test-invoices/{os.path.basename(file_path)}.txt")
|
|
|
|
if __name__ == '__main__':
|
|
# Teste lokale Dateien
|
|
test_files = [
|
|
'/tmp/test-invoices/rechnung_mit_mwst.pdf',
|
|
'/tmp/test-invoices/rechnung_ohne_mwst.pdf',
|
|
]
|
|
|
|
for test_file in test_files:
|
|
test_pdf_extraction(test_file)
|