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:
objectRun 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.
- 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.
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 recordsread_record(...): read one record by idsearch_count(...): count matching recordsget_model_fields(...): inspect field metadata viafields_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
OdooQueryfor common read-only accessUse
OdooCodeExecutoronly for trusted arbitrary codeallow_unsafe=Trueis still required for raw code execution