Odoo Connection Engine
Relevant source files
The following files were used as context for generating this wiki page:
Introduction
The Odoo Connection Engine is the core component of the OdooConnectorAPI, responsible for establishing and managing communication between the FastAPI application and the Odoo ERP system. It utilizes the odoorpc library to perform Remote Procedure Calls (RPC), allowing the API to authenticate, search for records, and read data from Odoo models.
The engine is designed to be highly configurable through environment variables, supporting local development via Docker Compose and production-grade deployments using Helm on Kubernetes. Its primary role is to abstract the complexities of the Odoo RPC protocol into a set of RESTful endpoints.
Sources: README.md:3-8, app/main.py:1-10
Connection Logic and Authentication
The connection process is initialized using parameters retrieved from the system environment. The engine uses these credentials to instantiate an odoorpc.ODOO object and perform a login operation against the target database.
Authentication Flow
The following sequence diagram illustrates the authentication and data retrieval process when a client requests partner information:
Connection Testing
A dedicated module odoo/test_odoo_connection.py provides a standalone method to verify connectivity outside of the FastAPI application context. This is used to ensure the Odoo 17 instance is reachable at the specified port and that credentials for the odoodb database are valid.
def test_odoo_connection():
"""Test connection to the Odoo server."""
odoo = odoorpc.ODOO('localhost', port=8069)
try:
odoo.login('odoodb', 'admin', 'admin') # Database, username, password
print("Successfully connected to Odoo 17!")
except ConnectionError as e:
print(f"Error connecting to Odoo 17: {e}")
Sources: odoo/test_odoo_connection.py:6-14
Configuration Management
The engine relies on four primary environment variables to establish a connection. These are injected into the application container during deployment.
| Variable | Description | Default (Dev) |
|---|---|---|
ODOO_URL | The hostname or IP address of the Odoo server. | localhost |
ODOO_DB | The name of the Odoo database to connect to. | mydb |
ODOO_USERNAME | The administrative username for authentication. | admin |
ODOO_PASSWORD | The password for the Odoo user. | admin |
Sources: app/main.py:11-15, charts/odooconnectorapi/values.yaml:18-22, docker-compose.yml:11-15
Infrastructure and Deployment
The connection engine is containerized and managed through different orchestration layers.
Container Architecture
The system architecture follows a decoupled pattern where the API acts as a gateway to the Odoo/PostgreSQL stack.
Kubernetes Integration
In Kubernetes environments, the engine's configuration is managed via the Helm chart's values.yaml and applied to the deployment template. This ensures that the ODOO_URL and other secrets are correctly mapped to the container's environment.
env:
- name: ODOO_URL
value: {{ .Values.env.ODOO_URL }}
- name: ODOO_DB
value: {{ .Values.env.ODOO_DB }}
Sources: charts/odooconnectorapi/templates/deployment.yaml:16-23
Data Interaction (res.partner)
The current implementation of the engine focuses on retrieving partner data. It follows a specific logic:
- Model Access: Accesses the
res.partnermodel viaodoo.env. - Search: Executes a search with an empty domain
[]to retrieve all partner IDs. - Read: Performs a read operation on the retrieved IDs, specifically requesting the
nameandemailfields. - Cleanup: Explicitly calls
odoo.logout()to terminate the session.
Sources: app/main.py:35-39
Summary
The Odoo Connection Engine provides a standardized way to interact with Odoo 17 using Python and FastAPI. By leveraging odoorpc and environment-based configuration, it enables seamless transitions between local development environments and scalable Kubernetes clusters, while maintaining secure and efficient access to ERP data.
Sources: README.md:5-15, app/main.py:1-5