Odoo Integration Flow
Relevant source files
The following files were used as context for generating this wiki page:
The Odoo Integration Flow serves as the core mechanism for the OdooConnectorAPI, enabling a RESTful interface to interact with an Odoo ERP instance. It bridges external client requests via FastAPI to Odoo's internal data structures using the odoorpc library. This integration is designed for containerized environments, supporting both Docker and Kubernetes deployments for scalability.
Sources: README.md:3-8, app/main.py:1-6
Architecture Overview
The integration follows a tiered architecture where a FastAPI application acts as a proxy. The application receives HTTP requests, authenticates with a remote Odoo server via RPC, performs data operations on specific Odoo models, and returns JSON responses to the client.
Component Interaction
The following diagram illustrates the high-level flow from a client request through the API to the Odoo backend and its PostgreSQL database.
This flow represents the communication path where the API translates REST calls into Odoo RPC commands.
Sources: app/main.py:22-38, odoo/docker-compose.yml:2-55
Authentication and Connection Logic
Connection to Odoo is established using the odoorpc.ODOO client. The system requires four primary parameters for authentication, which are typically injected via environment variables.
Connection Parameters
| Parameter | Description | Source File |
|---|---|---|
ODOO_URL | The hostname or IP of the Odoo server | app/main.py:10 |
ODOO_DB | The name of the target Odoo database | app/main.py:11 |
ODOO_USERNAME | The Odoo user account (e.g., admin) | app/main.py:12 |
ODOO_PASSWORD | The password for the Odoo user | app/main.py:13 |
Connection Sequence
The connection process involves initialization, login, environment access, and a final logout to release the session.
The application defaults to port 80 for production RPC calls within the FastAPI routes, while local testing scripts often target port 8069.
Sources: app/main.py:25-37, odoo/test_odoo_connection.py:7-13
Data Retrieval Flow
The specific flow for retrieving data, such as partner information, involves utilizing the Odoo ORM-like interface provided by odoorpc.
- Model Access: The API accesses the Odoo environment via
odoo.env. - Search: It performs a search on a specific model (e.g.,
res.partner) using a domain filter (e.g.,[]for all records). - Read: It reads specific fields from the discovered record IDs.
# Implementation of data retrieval in res.partner
if odoo.env:
partner = odoo.env['res.partner']
partners = partner.read(partner.search([]), ['name', 'email'])
Sources: app/main.py:33-36
Environment Configuration
The integration supports multiple deployment targets, each utilizing environment variables to configure the Odoo connection.
Configuration Sources
- Local Development: Environment variables are loaded from a
.envfile and managed bypython-dotenv. - Docker Compose: Variables are mapped directly in the
docker-compose.ymlfile under theenvironmentkey. - Kubernetes (Helm): Configured via the
values.yamlfile, which feeds into the deployment template's environment section.
# values.yaml example
env:
ODOO_URL: "localhost"
ODOO_DB: "mydb"
ODOO_USERNAME: "admin"
ODOO_PASSWORD: "admin"
Sources: README.md:38-41, docker-compose.yml:9-13, charts/odooconnectorapi/values.yaml:14-18
Error Handling
The integration flow includes basic error handling for RPC-specific failures. If the odoorpc client fails to log in or connect, an RPCError is caught, and the error details are returned in the JSON response.
try:
odoo = odoorpc.ODOO(ODOO_URL, port=80)
odoo.login(ODOO_DB, ODOO_USERNAME, ODOO_PASSWORD)
except odoorpc.error.RPCError as err:
return {"error": err}
Sources: app/main.py:25-29
Summary
The Odoo Integration Flow provides a structured path for external systems to query Odoo data. By encapsulating the odoorpc logic within FastAPI endpoints and providing flexible configuration through environment variables, the system ensures a consistent interface for managing ERP resources across local, Docker, and Kubernetes environments.