OdooQuery

The OdooQuery class provides a safe, structured read-only query API for common Odoo inspection tasks. It builds minimal trusted code internally and keeps the raw OdooCodeExecutor safety gate unchanged.

Safe read-only query helpers built on top of OdooCodeExecutor.

class oduit.odoo_query.OdooQuery(config: ConfigProvider | dict[str, Any])[source]

Bases: object

Run structured read-only queries against an Odoo environment.

This API is intended for common read-heavy tasks where callers should not need to pass arbitrary Python code strings. It validates structured input, generates minimal trusted code internally, and relies on the executor’s default rollback behavior.

__init__(config: ConfigProvider | dict[str, Any])[source]
query_model(model: str, domain: list[Any] | tuple[Any, ...] | None = None, fields: list[str] | tuple[str, ...] | None = None, limit: int = 80, include_total_count: bool = False, database: str | None = None, timeout: float = 30.0) dict[str, Any][source]

Search records and return read data for the matched result set.

read_record(model: str, record_id: int, fields: list[str] | tuple[str, ...] | None = None, database: str | None = None, timeout: float = 30.0) dict[str, Any][source]

Read one record by id.

search_count(model: str, domain: list[Any] | tuple[Any, ...] | None = None, database: str | None = None, timeout: float = 30.0) dict[str, Any][source]

Return the number of records matching a domain.

get_model_fields(model: str, attributes: list[str] | tuple[str, ...] | None = None, module: str | None = None, database: str | None = None, timeout: float = 30.0) dict[str, Any][source]

Inspect field metadata for a model via fields_get.

Basic Usage

from oduit import OdooQuery

query = OdooQuery(
    {
        "db_name": "mydb",
        "db_user": "odoo",
        "addons_path": "/opt/odoo/addons",
    }
)

result = query.query_model(
    "res.partner",
    domain=[("customer_rank", ">", 0)],
    fields=["name", "email"],
    limit=5,
)

if result["success"]:
    print(result["records"])

Supported Read Helpers

  • query_model(...): search and read matching records

  • read_record(...): read one record by id

  • search_count(...): count matching records

  • get_model_fields(...): inspect field metadata via fields_get

If you prefer a single high-level entry point, the same read helpers are also available on OdooOperations and return typed dataclass wrappers.

Validation Rules

  • Model names must use safe identifier characters

  • Fields and attribute names must be string identifiers

  • Domains must contain literal-safe values only

  • Query limits must be positive integers and stay within the built-in cap

Relationship To OdooCodeExecutor

  • Use OdooQuery for common read-only access

  • Use OdooCodeExecutor only for trusted arbitrary code

  • allow_unsafe=True is still required for raw code execution