Skip to content

feat: odoo direct integration#218

Draft
esafwan wants to merge 8 commits into
developfrom
feat/odoo-first-class-integration
Draft

feat: odoo direct integration#218
esafwan wants to merge 8 commits into
developfrom
feat/odoo-first-class-integration

Conversation

@esafwan
Copy link
Copy Markdown
Contributor

@esafwan esafwan commented Mar 24, 2026

First-Class Odoo ERP Integration for HUF

image

This PR implements native Odoo ERP integration into HUF, enabling AI agents to interact with Odoo instances via a protocol-agnostic RPC engine, respond to business events in real-time, and query/mutate data across all Odoo modules.

Scope: Odoo 17+ only | New code: ~880 lines across 13 files | Breaking changes: None


Why This Matters

Odoo is the most widely deployed open-source ERP. Until now, connecting HUF agents to Odoo required custom tool functions per customer. This integration makes Odoo a first-class citizen — any HUF agent can search, create, update, delete, and execute methods on any Odoo model out of the box.


Architecture

Five tightly integrated subsystems:

┌─────────────────────────────────────────────────────┐
│                   HUF Agent                         │
│         (uses Odoo tools in conversations)          │
├─────────────────────────────────────────────────────┤
│              10 Odoo Tool Handlers                  │
│   search_read · read · create · write · unlink      │
│   execute · fields_get · list_models                │
│   search_count · read_group                         │
├─────────────────────────────────────────────────────┤
│           OdooConnector (protocol-agnostic)         │
│          Rate-limited · Connection-scoped           │
├──────────┬──────────────┬───────────────────────────┤
│ XML-RPC  │  JSON-RPC    │  JSON-2 (Odoo 19+)       │
│ (legacy) │  (17–18)     │  Bearer token + REST      │
└──────────┴──────────────┴───────────────────────────┘
          ↕                        ↕
    Odoo Instance              Odoo Instance

Event flow (Odoo → HUF):

Odoo record event
    ├── Path A: Webhook POST → /api/method/huf.ai.odoo.webhook.receive_webhook
    │           (real-time, requires Odoo-side config or companion module)
    │
    ├── Path B: Polling cron (*/5 * * * *) → write_date > last_sync
    │           (universal fallback, 5-min latency)
    │
    └── Both → match Agent Triggers → enqueue background job → run_agent_sync()

What's Included

1. Odoo Connection DocType

Stores credentials, protocol, version, and connection state. Key fields:

Field Type Notes
odoo_url Data Instance URL (validated)
database_name Data Odoo DB name
api_key Password Encrypted via Frappe Password field
auth_method Select API Key (default) or Password
odoo_version Select 17, 18, 19, or Auto Detect
protocol Select JSON-RPC, XML-RPC, JSON-2, or Auto
webhook_key Password Auto-generated 32-char hex, encrypted
webhook_url Data Computed, read-only
rate_limit_rpm Int Default 60 (respects Odoo SaaS throttling)

Backward Compatibility

  • No breaking changes. All Odoo functionality is opt-in.
  • New odoo_connection field on Agent DocType is hidden unless Odoo tools are present.
  • New cron entry is non-blocking.
  • Customers without Odoo connections are completely unaffected.

Test Plan

  • bench --site <site> migrate applies cleanly
  • Both crons register: polling.run_polling_sync (/5) and orchestration.scheduler.process_orchestrations (/1)
  • Create Odoo Connection → test_connection() succeeds against Odoo 17/18/19
  • 10 tools callable from agent chat (search_read, create, write, etc.)
  • Webhook endpoint validates key and triggers agents
  • Polling picks up modified records within 5-minute window
  • Schema discovery caches model fields
  • Rate limiter throttles concurrent requests

esafwan added 8 commits March 24, 2026 23:04
10-phase implementation plan for making HUF the #1 AI automation
system for Odoo ERP. Covers:

- Phase 1: Odoo Connection DocType (credential management)
- Phase 2: RPC Connector Core (XML-RPC, JSON-RPC, JSON-2)
- Phase 3: Odoo-specific Agent Tool Functions (10 tools)
- Phase 4: Schema Discovery & Cache (via fields_get/ir.model)
- Phase 5: Webhook Receiver (inbound events from base.automation)
- Phase 6: Polling Trigger Service (adaptive write_date polling)
- Phase 7: Pre-built Odoo Agents (CRM, Sales, Invoice, etc.)
- Phase 8: JSON-2 API Support (Odoo 19+ future-proofing)
- Phase 9: Frontend Connection Wizard
- Phase 10: Documentation & Guides

Based on deep research analysis of Odoo's API landscape,
authentication models, hosting constraints, and deprecation timeline.

21 new files, 5 modified files planned across all phases.
- Implemented missing tool handlers (search_count, read_group)
- Refactored RateLimiter to use shared connection-scoped cache
- Converted polling sync to async enqueuing for better performance
- Optimized Schema Discovery with O(1) indexing and abstract model handling
- Secured Webhook keys using Password fields and connection routing
- Added Agent-level odoo_connection for auto-injection into tool calls
- Updated AGENTS.md and SKILL details to reflect architectural refinements
Python dict duplicate keys silently overwrite — the second "cron" key
was replacing the first, causing odoo polling to never run.

https://claude.ai/code/session_01Uk76A2xXqimHUAaE3nBPeP
…limitation

Odoo has NO native webhook system. The current integration uses polling
(every 5 min via write_date) and an inbound webhook receiver that requires
manual base.automation setup on the Odoo side.

This document designs a thin companion Odoo module (huf_connector) that:
- Patches ORM create/write/unlink via _register_hook() on selected models
- Pushes events to HUF in real-time without manual per-model setup
- Covers ALL Odoo modules (CRM, Sales, Inventory, HR, etc.) generically
- Includes a setup wizard for one-click configuration
- Supports batched event flushing to avoid flooding HUF

Polling remains necessary as fallback for Odoo SaaS Standard customers
who cannot install custom modules.

https://claude.ai/code/session_01Uk76A2xXqimHUAaE3nBPeP
…ib eval

- Odoo 18+ has native "Send Webhook Notification" automation actions
- Odoo 17 has inbound "External trigger" but no outbound webhooks
- Odoo 15-16 has no webhook support at all
- Added decision matrix: companion module vs native webhooks vs polling
- Added evaluation of odoo-client-lib as transport layer replacement
- Not currently using odoo-client-lib; recommend evaluating for Phase 2

https://claude.ai/code/session_01Uk76A2xXqimHUAaE3nBPeP
- Drop Odoo 15-16 from support scope, 17+ only going forward
- Replace vague odoo-client-lib recommendation with exact migration steps:
  7 steps, 6 files touched, zero caller changes needed
- Update decision matrix and version tables for 17+ scope
- Companion module manifest updated for multi-version branching

https://claude.ai/code/session_01Uk76A2xXqimHUAaE3nBPeP
- Replaced hand-rolled RPC protocols with odoo-client-lib
- Simplified OdooConnector and improved protocol auto-detection
- Removed legacy protocols/ directory and internal RPC exceptions
- Updated test_connection() to use unified transport path
- Added odoo-client-lib to pyproject.toml
@esafwan esafwan requested a review from Sanjusha-tridz March 25, 2026 08:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant