- Updated billing frontend views to use Jinja2 templates for rendering HTML pages. - Added support for displaying supplier invoices, template builder, and templates list with titles. - Introduced a new configuration setting for company CVR number. - Enhanced OllamaService to support credit notes in invoice extraction, including detailed JSON output format. - Improved PDF text extraction using pdfplumber for better layout handling. - Added a modal for editing vendor details with comprehensive fields and validation. - Implemented invoice loading and display functionality in vendor detail view. - Updated vendor management to remove priority handling and improve error messaging. - Added tests for AI analyze endpoint and CVR filtering to ensure correct behavior. - Created migration script to support credit notes in the database schema.
49 lines
1.6 KiB
Python
49 lines
1.6 KiB
Python
#!/usr/bin/env python3
|
|
"""Test AI analyze endpoint med CVR filter"""
|
|
import requests
|
|
import pdfplumber
|
|
import json
|
|
from pathlib import Path
|
|
|
|
# Extract PDF text
|
|
pdf_path = Path("uploads/5082481.pdf")
|
|
all_text = []
|
|
with pdfplumber.open(pdf_path) as pdf:
|
|
for page in pdf.pages:
|
|
page_text = page.extract_text(layout=True, x_tolerance=2, y_tolerance=2)
|
|
if page_text:
|
|
all_text.append(page_text)
|
|
|
|
full_text = "\n".join(all_text)
|
|
|
|
# Call AI analyze endpoint
|
|
print("🧪 Testing AI analyze endpoint...")
|
|
response = requests.post(
|
|
'http://localhost:8000/api/v1/supplier-invoices/ai/analyze',
|
|
json={'pdf_text': full_text[:2000]}, # First 2000 chars as in the actual code
|
|
headers={'Content-Type': 'application/json'}
|
|
)
|
|
|
|
print(f"Status: {response.status_code}")
|
|
|
|
if response.status_code == 200:
|
|
result = response.json()
|
|
print(f"\n✅ AI Analysis Result:")
|
|
print(f" CVR: {result.get('cvr')}")
|
|
print(f" Invoice Number: {result.get('invoice_number')}")
|
|
print(f" Date: {result.get('invoice_date')}")
|
|
print(f" Total: {result.get('total_amount')}")
|
|
print(f" Detection Patterns: {result.get('detection_patterns')}")
|
|
|
|
# Check CVR filter
|
|
found_cvr = result.get('cvr')
|
|
OWN_CVR = "44687369"
|
|
if found_cvr == OWN_CVR:
|
|
print(f"\n❌ FAIL: AI returned OWN_CVR {OWN_CVR} - filter didn't work!")
|
|
elif found_cvr == "29522790":
|
|
print(f"\n✅ PASS: AI found correct vendor CVR {found_cvr} (DCS ApS)")
|
|
else:
|
|
print(f"\n⚠️ WARNING: AI found CVR {found_cvr} - unexpected value")
|
|
else:
|
|
print(f"❌ Error: {response.text}")
|