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.
3.9 KiB
3.9 KiB
name, description
| name | description |
|---|---|
| odoo-xml-import | Use this skill when generating, validating, or modifying Odoo Enterprise XML import files from extracted invoice data in the odoo_ocr project. |
Odoo XML Import Skill
Use this skill whenever you need to produce Odoo XML from the ExtractedInvoice schema.
Target Format
Generate standard Odoo data-import XML:
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<data>
<record id="vendor_x" model="res.partner">
<field name="name">...</field>
<field name="supplier_rank">1</field>
</record>
<record id="invoice_123" model="account.move">
<field name="move_type">in_invoice</field>
<field name="partner_id" ref="vendor_x"/>
<field name="invoice_date">2024-05-01</field>
<field name="date">2024-05-01</field>
<field name="invoice_date_due">2024-06-01</field>
<field name="ref">INV-123</field>
<field name="currency_id" ref="base.USD"/>
<field name="narration">...</field>
</record>
<record id="invoice_123_line_1" model="account.move.line">
<field name="move_id" ref="invoice_123"/>
<field name="name">Product A</field>
<field name="quantity">2</field>
<field name="price_unit">100.00</field>
<field name="tax_ids" eval="[(6, 0, [ref('tax_15')])]"/>
</record>
<record id="tax_15" model="account.tax">
<field name="name">VAT 15%</field>
<field name="amount">15</field>
<field name="amount_type">percent</field>
<field name="type_tax_use">purchase</field>
</record>
</data>
</odoo>
See templates/invoice_import.xml for a full template.
Required Records
Every XML file must create or reference:
-
Vendor (
res.partner)name(required)supplier_rank= 1- optional:
vat,street,city,zip,country_id
-
Vendor Bill (
account.move)move_type=in_invoicepartner_idref to vendor recordinvoice_date(required)date(defaults to invoice_date)invoice_date_due(optional)ref= invoice numbercurrency_id(defaults from settings; map common ISO codes tobase.*refs)narration= summary / payment terms (optional)
-
Invoice Lines (
account.move.line)- One record per
line_itemsentry. move_idref to vendor bill.name= line description.quantity,price_unit(decimal strings).tax_idseval with refs to existing or newly created tax records.- Do not set
debit/creditdirectly; Odoo will compute them from price_unit × quantity.
- One record per
-
Taxes (
account.tax)- Create only if the tax does not already exist.
- Use deterministic external ID based on rate and type, e.g.,
purchase_vat_15. name,amount,amount_type='percent',type_tax_use='purchase'.
External ID Rules
- Sanitize IDs: lowercase, replace non-alphanumeric with
_, strip leading digits. - Vendor ID:
vendor_<sanitized_name>_<hash>or use VAT if present. - Invoice ID:
invoice_<sanitized_number>_<date>with hash if needed for uniqueness. - Tax ID:
purchase_vat_<rate>.
Validation Rules
- Parse generated XML with
lxml.etree. - Ensure required fields are present and non-empty.
- Warn if
sum(line totals) + tax != totalbeyond rounding tolerance (0.01). - If
human_review_requiredflag is set, add an XML comment or metadata record documenting this.
Implementation Location
All XML logic lives in src/odoo_ocr/pipeline/xml_builder.py and src/odoo_ocr/schemas/odoo_xml.py.
Currency Mapping
Maintain a hardcoded fallback map from ISO code to base.<code> for common currencies (EUR, USD, GBP, CHF). If a currency is not in the map, create a res.currency record or default to settings.
Testing
- Test XML generation against a known-good sample in
tests/fixtures/expected_invoice.xml. - Validate that generated XML is parseable and contains the required records.