Connection Testing Script
Relevant source files
The following files were used as context for generating this wiki page:
The Connection Testing Script is a utility within the OdooConnectorAPI project designed to verify connectivity between the application environment and a target Odoo ERP instance. It serves as a diagnostic tool to ensure that the odoorpc library can successfully authenticate and communicate with the Odoo XML-RPC interface using provided credentials.
This script is critical during the initial setup phase and for troubleshooting environment configuration issues, such as incorrect network routing or invalid credentials. It mirrors the connection logic used in the main FastAPI application but operates as a standalone Python execution.
Functional Architecture
The script utilizes the odoorpc library to establish a connection to the Odoo server. It attempts to perform a login operation, which is the standard method for validating access to specific Odoo databases.
Execution Flow
The following diagram illustrates the logical flow of the connection test:
The script specifically targets a local Odoo instance during manual testing, typical for environments orchestrated via Docker Compose.
Sources: odoo/test_odoo_connection.py:6-14, odoo/docker-compose.yml:25-30
Configuration and Parameters
The connection script uses hardcoded defaults for local testing, which align with the services defined in the Odoo infrastructure deployment. In the production application, these parameters are typically injected via environment variables.
| Parameter | Script Default | Service Reference | Description |
|---|---|---|---|
| Host | localhost | web service | The hostname or IP of the Odoo server. |
| Port | 8069 | 8069:8069 | The port Odoo is listening on. |
| Database | odoodb | POSTGRES_DB | The target Odoo database name. |
| User | admin | N/A | The username for Odoo authentication. |
| Password | admin | N/A | The password for Odoo authentication. |
Sources: odoo/test_odoo_connection.py:8-10, odoo/docker-compose.yml:25-30, app/main.py:10-13
Technical Implementation
The implementation relies on the odoorpc package, which is listed as a core dependency for the project. The script handles basic exception management to identify ConnectionError events during the login handshake.
Core Connection Logic
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, requirements.txt:3
Integration with Odoo 17
The script is specifically configured to validate connections against Odoo version 17, as indicated by the docker image specification and the console output messages within the script.
Relationship to Main Application
While the testing script is a standalone utility, the app/main.py file uses a similar pattern for its Odoo integration. The main application expands on this by fetching data (e.g., partners) after a successful login and using environment variables for configuration.
- Shared Library: Both use
odoorpcfor communication. - Authentication: Both perform a
login()call before executing commands. - Error Handling: The script catches
ConnectionError, while the API catchesodoorpc.error.RPCError.
Sources: app/main.py:24-38, odoo/test_odoo_connection.py:10-13
Summary
The Connection Testing Script provides a lightweight mechanism to verify the reachability and credentials of an Odoo instance. By utilizing the same odoorpc library as the production FastAPI application, it ensures that if the test script succeeds, the API's underlying communication layer is also correctly configured.