7e706793fa
- Add AGENTS.md and project-specific Zed skills (odoo-ocr-pipeline, odoo-xml-import, local-vlm-client). - Implement Pydantic schemas for documents, invoices, review results, and VLM responses. - Add unified BaseVLMClient with Ollama implementation and llama.cpp stub. - Build pipeline stages: loader, classifier, digital_pdf/scanned_print/handwritten/mixed_unknown branches, extractor, reviewer, xml_builder. - Add CLI entry point with sidecar JSON and confidence-gated XML output. - Include prompts for classifier, OCR, extraction, and review models. - Add tests with FakeVLMClient; pytest, ruff, and mypy all pass.
61 lines
1.8 KiB
Python
61 lines
1.8 KiB
Python
"""Tests for the Odoo XML builder."""
|
|
|
|
from decimal import Decimal
|
|
|
|
from odoo_ocr.config import Settings
|
|
from odoo_ocr.pipeline.xml_builder import build_odoo_xml
|
|
from odoo_ocr.schemas import ExtractedInvoice, InvoiceLineItem, ReviewResult
|
|
|
|
|
|
def test_build_odoo_xml() -> None:
|
|
settings = Settings()
|
|
invoice = ExtractedInvoice(
|
|
vendor_name="Acme Supplies",
|
|
vendor_vat="GB123456789",
|
|
invoice_number="INV-2024-001",
|
|
invoice_date="2024-05-01",
|
|
due_date="2024-06-01",
|
|
currency="EUR",
|
|
payment_terms="Net 30",
|
|
line_items=[
|
|
InvoiceLineItem(
|
|
description="Consulting services",
|
|
quantity=Decimal("10.0"),
|
|
unit_price=Decimal("100.00"),
|
|
total_price=Decimal("1000.00"),
|
|
tax_rate=Decimal("20"),
|
|
)
|
|
],
|
|
subtotal=Decimal("1000.00"),
|
|
tax_total=Decimal("200.00"),
|
|
total=Decimal("1200.00"),
|
|
)
|
|
review = ReviewResult(valid=True, confidence=0.95)
|
|
|
|
xml = build_odoo_xml(invoice, review, settings)
|
|
|
|
assert xml.startswith("<?xml version=")
|
|
assert 'model="res.partner"' in xml
|
|
assert 'model="account.move"' in xml
|
|
assert 'model="account.move.line"' in xml
|
|
assert "Acme Supplies" in xml
|
|
assert "INV-2024-001" in xml
|
|
assert "in_invoice" in xml
|
|
|
|
|
|
def test_xml_adds_review_comment_for_low_confidence() -> None:
|
|
settings = Settings()
|
|
invoice = ExtractedInvoice(
|
|
vendor_name="X",
|
|
invoice_number="1",
|
|
invoice_date="2024-01-01",
|
|
line_items=[],
|
|
subtotal=Decimal("0"),
|
|
tax_total=Decimal("0"),
|
|
total=Decimal("0"),
|
|
)
|
|
review = ReviewResult(valid=False, confidence=0.80)
|
|
|
|
xml = build_odoo_xml(invoice, review, settings)
|
|
assert "HUMAN REVIEW ADVISED" in xml
|