Skip to content

Generic CRUD

GenericNamespace for generic model operations that work with any Odoo model, accessed as client.generic.

generic

Generic Odoo model operations.

GenericNamespace

GenericNamespace(client: OdooClient)

Generic model operations for any Odoo model.

Source code in src/vodoo/generic.py
def __init__(self, client: OdooClient) -> None:
    self._client = client

create

create(model: str, values: dict[str, Any]) -> int

Create a new record.

PARAMETER DESCRIPTION
model

Model name (e.g., 'product.template')

TYPE: str

values

Dictionary of field values

TYPE: dict[str, Any]

RETURNS DESCRIPTION
int

ID of created record

Examples:

>>> ns.create('res.partner', {'name': 'John Doe', 'email': 'john@example.com'})
42
Source code in src/vodoo/generic.py
def create(self, model: str, values: dict[str, Any]) -> int:
    """Create a new record.

    Args:
        model: Model name (e.g., 'product.template')
        values: Dictionary of field values

    Returns:
        ID of created record

    Examples:
        >>> ns.create('res.partner', {'name': 'John Doe', 'email': 'john@example.com'})
        42

    """
    return self._client.create(model, values)

update

update(model: str, record_id: int, values: dict[str, Any]) -> bool

Update a record.

PARAMETER DESCRIPTION
model

Model name

TYPE: str

record_id

Record ID

TYPE: int

values

Dictionary of field values to update

TYPE: dict[str, Any]

RETURNS DESCRIPTION
bool

True if successful

Examples:

>>> ns.update('res.partner', 42, {'phone': '+1234567890'})
True
Source code in src/vodoo/generic.py
def update(self, model: str, record_id: int, values: dict[str, Any]) -> bool:
    """Update a record.

    Args:
        model: Model name
        record_id: Record ID
        values: Dictionary of field values to update

    Returns:
        True if successful

    Examples:
        >>> ns.update('res.partner', 42, {'phone': '+1234567890'})
        True

    """
    return self._client.write(model, [record_id], values)

delete

delete(model: str, record_id: int) -> bool

Delete a record.

PARAMETER DESCRIPTION
model

Model name

TYPE: str

record_id

Record ID

TYPE: int

RETURNS DESCRIPTION
bool

True if successful

Examples:

>>> ns.delete('res.partner', 42)
True
Source code in src/vodoo/generic.py
def delete(self, model: str, record_id: int) -> bool:
    """Delete a record.

    Args:
        model: Model name
        record_id: Record ID

    Returns:
        True if successful

    Examples:
        >>> ns.delete('res.partner', 42)
        True

    """
    return self._client.unlink(model, [record_id])

search

search(model: str, domain: list[Any] | None = None, fields: list[str] | None = None, limit: int | None = None, offset: int = 0, order: str | None = None) -> list[dict[str, Any]]

Search and read records.

PARAMETER DESCRIPTION
model

Model name

TYPE: str

domain

Search domain

TYPE: list[Any] | None DEFAULT: None

fields

Fields to fetch

TYPE: list[str] | None DEFAULT: None

limit

Maximum number of records

TYPE: int | None DEFAULT: None

offset

Number of records to skip

TYPE: int DEFAULT: 0

order

Sort order

TYPE: str | None DEFAULT: None

RETURNS DESCRIPTION
list[dict[str, Any]]

List of record dictionaries

Examples:

>>> ns.search('res.partner', [['name', 'ilike', 'john']])
[{'id': 42, 'name': 'John Doe', ...}]
Source code in src/vodoo/generic.py
def search(
    self,
    model: str,
    domain: list[Any] | None = None,
    fields: list[str] | None = None,
    limit: int | None = None,
    offset: int = 0,
    order: str | None = None,
) -> list[dict[str, Any]]:
    """Search and read records.

    Args:
        model: Model name
        domain: Search domain
        fields: Fields to fetch
        limit: Maximum number of records
        offset: Number of records to skip
        order: Sort order

    Returns:
        List of record dictionaries

    Examples:
        >>> ns.search('res.partner', [['name', 'ilike', 'john']])
        [{'id': 42, 'name': 'John Doe', ...}]

    """
    return self._client.search_read(
        model,
        domain=domain,
        fields=fields,
        limit=limit,
        offset=offset,
        order=order,
    )

call

call(model: str, method: str, args: list[Any] | None = None, kwargs: dict[str, Any] | None = None) -> Any

Call a custom method on a model.

PARAMETER DESCRIPTION
model

Model name

TYPE: str

method

Method name

TYPE: str

args

Positional arguments

TYPE: list[Any] | None DEFAULT: None

kwargs

Keyword arguments

TYPE: dict[str, Any] | None DEFAULT: None

RETURNS DESCRIPTION
Any

Method result

Examples:

>>> ns.call('res.partner', 'name_search', args=['Acme'])
[(1, 'Acme Corp'), (2, 'Acme Ltd')]
Source code in src/vodoo/generic.py
def call(
    self,
    model: str,
    method: str,
    args: list[Any] | None = None,
    kwargs: dict[str, Any] | None = None,
) -> Any:
    """Call a custom method on a model.

    Args:
        model: Model name
        method: Method name
        args: Positional arguments
        kwargs: Keyword arguments

    Returns:
        Method result

    Examples:
        >>> ns.call('res.partner', 'name_search', args=['Acme'])
        [(1, 'Acme Corp'), (2, 'Acme Ltd')]

    """
    args = args or []
    kwargs = kwargs or {}

    return self._client.execute(model, method, *args, **kwargs)