Odoo RPC Client

Odoo RPC Client for interacting with Odoo’s external API.

This module provides a singleton client for making RPC calls to an Odoo instance. It handles connection management, authentication, and provides common operations.

class prs_commons.odoo.OdooRPCClient[source]

Bases: object

A singleton client for making RPC calls to an Odoo instance.

This client handles connection management, authentication, and provides methods for common Odoo operations. It’s implemented as a singleton to maintain a single connection pool.

Environment Variables:

ODOO_HOST: The hostname of the Odoo server ODOO_DB: The database name ODOO_LOGIN: The login username ODOO_PASSWORD: The login password

create_record(model: str, values: Dict[str, Any]) int[source]

Create a new record in the specified model.

Parameters:
  • model – The Odoo model name

  • values – Dictionary of field values

Returns:

The ID of the created record

ensure_connection() None[source]

Ensure that we have a valid connection to the Odoo server.

execute_method(model: str, method: str, ids: List[int], *args: Any, **kwargs: Any) Any[source]

Execute a method on a specified model for given record IDs.

Parameters:
  • model – The Odoo model name (e.g., ‘event.registration’)

  • method – The method name to call

  • ids – List of record IDs to operate on

  • *args – Positional arguments to pass to the method

  • **kwargs – Keyword arguments to pass to the method

Returns:

The result of the method call

Raises:

Exception – If the method execution fails

search_read(model: str, domain: List[tuple], fields: List[str] | None = None, offset: int = 0, limit: int | None = None, order: str | None = None) List[Dict[str, Any]][source]

Search and read records from a model.

Parameters:
  • model – The Odoo model name

  • domain – Search domain

  • fields – List of fields to return

  • offset – Number of records to skip

  • limit – Maximum number of records to return

  • order – Sort order

Returns:

List of dictionaries containing the requested fields for each record

write_record(model: str, ids: List[int], values: Dict[str, Any]) bool[source]

Update existing records.

Parameters:
  • model – The Odoo model name

  • ids – List of record IDs to update

  • values – Dictionary of field values to update

Returns:

True if the update was successful

OdooRPCClient

class prs_commons.odoo.OdooRPCClient[source]

Bases: object

A singleton client for making RPC calls to an Odoo instance.

This client handles connection management, authentication, and provides methods for common Odoo operations. It’s implemented as a singleton to maintain a single connection pool.

Environment Variables:

ODOO_HOST: The hostname of the Odoo server ODOO_DB: The database name ODOO_LOGIN: The login username ODOO_PASSWORD: The login password

__init__() None[source]

Initialize the Odoo RPC client with environment configuration.

ensure_connection() None[source]

Ensure that we have a valid connection to the Odoo server.

execute_method(model: str, method: str, ids: List[int], *args: Any, **kwargs: Any) Any[source]

Execute a method on a specified model for given record IDs.

Parameters:
  • model – The Odoo model name (e.g., ‘event.registration’)

  • method – The method name to call

  • ids – List of record IDs to operate on

  • *args – Positional arguments to pass to the method

  • **kwargs – Keyword arguments to pass to the method

Returns:

The result of the method call

Raises:

Exception – If the method execution fails

search_read(model: str, domain: List[tuple], fields: List[str] | None = None, offset: int = 0, limit: int | None = None, order: str | None = None) List[Dict[str, Any]][source]

Search and read records from a model.

Parameters:
  • model – The Odoo model name

  • domain – Search domain

  • fields – List of fields to return

  • offset – Number of records to skip

  • limit – Maximum number of records to return

  • order – Sort order

Returns:

List of dictionaries containing the requested fields for each record

create_record(model: str, values: Dict[str, Any]) int[source]

Create a new record in the specified model.

Parameters:
  • model – The Odoo model name

  • values – Dictionary of field values

Returns:

The ID of the created record

write_record(model: str, ids: List[int], values: Dict[str, Any]) bool[source]

Update existing records.

Parameters:
  • model – The Odoo model name

  • ids – List of record IDs to update

  • values – Dictionary of field values to update

Returns:

True if the update was successful

create_record(model: str, values: Dict[str, Any]) int[source]

Create a new record in the specified model.

Parameters:
  • model – The Odoo model name

  • values – Dictionary of field values

Returns:

The ID of the created record

ensure_connection() None[source]

Ensure that we have a valid connection to the Odoo server.

execute_method(model: str, method: str, ids: List[int], *args: Any, **kwargs: Any) Any[source]

Execute a method on a specified model for given record IDs.

Parameters:
  • model – The Odoo model name (e.g., ‘event.registration’)

  • method – The method name to call

  • ids – List of record IDs to operate on

  • *args – Positional arguments to pass to the method

  • **kwargs – Keyword arguments to pass to the method

Returns:

The result of the method call

Raises:

Exception – If the method execution fails

search_read(model: str, domain: List[tuple], fields: List[str] | None = None, offset: int = 0, limit: int | None = None, order: str | None = None) List[Dict[str, Any]][source]

Search and read records from a model.

Parameters:
  • model – The Odoo model name

  • domain – Search domain

  • fields – List of fields to return

  • offset – Number of records to skip

  • limit – Maximum number of records to return

  • order – Sort order

Returns:

List of dictionaries containing the requested fields for each record

write_record(model: str, ids: List[int], values: Dict[str, Any]) bool[source]

Update existing records.

Parameters:
  • model – The Odoo model name

  • ids – List of record IDs to update

  • values – Dictionary of field values to update

Returns:

True if the update was successful