Skip to content

Products

This page documents how to use the manager and record objects for products.

Details

Name Value
Odoo Modules Product, Accounting, Sales
Odoo Model Name product.product
Manager products
Record Type Product

Manager

The product manager is available as the products attribute on the Odoo client object.

>>> from openstack_odooclient import Client as OdooClient
>>> odoo_client = OdooClient(
...     hostname="localhost",
...     port=8069,
...     protocol="jsonrpc",
...     database="odoodb",
...     user="test-user",
...     password="<password>",
... )
>>> odoo_client.products.get(1234)
Product(record={'id': 1234, ...}, fields=None)

For more information on how to use managers, refer to Managers.

The following manager methods are also available, in addition to the standard methods.

get_sellable_company_products

get_sellable_company_products(
    company: int | Company,
    fields: Iterable[str] | None = None,
    order: str | None = None,
    as_id: bool = False,
    as_dict: bool = False,
) -> list[Product]
get_sellable_company_products(
    company: int | Company,
    fields: Iterable[str] | None = None,
    order: str | None = None,
    as_id: bool = True,
    as_dict: bool = False,
) -> list[int]
get_sellable_company_products(
    company: int | Company,
    fields: Iterable[str] | None = None,
    order: str | None = None,
    as_id: bool = False,
    as_dict: bool = True,
) -> list[dict[str, Any]]

Fetch a list of active and saleable products for the given company.

>>> from openstack_odooclient import Client as OdooClient
>>> odoo_client = OdooClient(
...     hostname="localhost",
...     port=8069,
...     protocol="jsonrpc",
...     database="odoodb",
...     user="test-user",
...     password="<password>",
... )
>>> odoo_client.products.get_sellable_company_products(
...     company=1234,  # ID or object
... )
[Product(record={'id': 5678, ...}, fields=None), ...]

Parameters

Name Type Description Default
company int | Company The company to search for products (ID or object) (required)
fields Iterable[str] | None Fields to select, defaults to None (select all) None
order str | None Order results by a specific field None
as_id bool Return the record IDs only False
as_dict bool Return records as dictionaries False

Returns

Type Description
list[Product] List of product objects (default)
list[int] List of product IDs (when as_id is True)
list[dict[str, Any]] List of product dictionaries (when as_dict is True)

get_sellable_company_product_by_name

get_sellable_company_product_by_name(
    company: int | Company,
    name: str,
    fields: Iterable[str] | None = None,
    order: str | None = None,
    as_id: bool = False,
    as_dict: bool = False,
    optional: bool = False,
) -> Product
get_sellable_company_product_by_name(
    company: int | Company,
    name: str,
    fields: Iterable[str] | None = None,
    order: str | None = None,
    as_id: bool = False,
    as_dict: bool = False,
    optional: bool = True,
) -> Product | None
get_sellable_company_product_by_name(
    company: int | Company,
    name: str,
    fields: Iterable[str] | None = None,
    order: str | None = None,
    as_id: bool = True,
    as_dict: bool = False,
    optional: bool = False,
) -> int
get_sellable_company_product_by_name(
    company: int | Company,
    name: str,
    fields: Iterable[str] | None = None,
    order: str | None = None,
    as_id: bool = True,
    as_dict: bool = False,
    optional: bool = True,
) -> int | None
get_sellable_company_product_by_name(
    company: int | Company,
    name: str,
    fields: Iterable[str] | None = None,
    order: str | None = None,
    as_id: bool = False,
    as_dict: bool = True,
    optional: bool = False,
) -> dict[str, Any]
get_sellable_company_product_by_name(
    company: int | Company,
    name: str,
    fields: Iterable[str] | None = None,
    order: str | None = None,
    as_id: bool = False,
    as_dict: bool = True,
    optional: bool = True,
) -> dict[str, Any] | None

Query a unique product for the given company by name.

>>> from openstack_odooclient import Client as OdooClient
>>> odoo_client = OdooClient(
...     hostname="localhost",
...     port=8069,
...     protocol="jsonrpc",
...     database="odoodb",
...     user="test-user",
...     password="<password>",
... )
>>> odoo_client.products.get_sellable_company_product_by_name(
...     company=1234,
...     name="RegionOne.m1.small",
... )
Product(record={'id': 5678, 'name': 'RegionOne.m1.small', ...}, fields=None)

A number of parameters are available to configure the return type, and what happens when a result is not found.

By default all fields available on the record model will be selected, but this can be filtered using the fields parameter.

Use the as_id parameter to return the ID of the record, instead of the record object.

Use the as_dict parameter to return the record as a dict object, instead of a record object.

When optional is True, None is returned if a record with the given name does not exist, instead of raising an error.

Parameters

Name Type Description Default
company int | Company The company to search for products (ID or object) (required)
name str The product name (required)
fields Iterable[str] | None Fields to select, defaults to None (select all) None
as_id bool Return a record ID False
as_dict bool Return the record as a dictionary False
optional bool Return None if not found False

Raises

Type Description
MultipleRecordsFoundError Multiple records with the same name were found
RecordNotFoundError Record with the given name not found (when optional is False)

Returns

Type Description
Product Product object (default)
int Product ID (when as_id is True)
dict[str, Any] Product dictionary (when as_dict is True)
None If a product with the given name was not found (when optional is True)

Record

The product manager returns Product record objects.

To import the record class for type hinting purposes:

from openstack_odooclient import Product

The record class currently implements the following fields and methods.

For more information on attributes and methods common to all record types, see Record Attributes and Methods.

categ_id

categ_id: int

The ID for the category this product is under.

categ_name

categ_name: str

The name of the category this product is under.

categ

categ: ProductCategory

The category this product is under.

This fetches the full record from Odoo once, and caches it for subsequent accesses.

company_id

company_id: int | None

The ID for the company that owns this product, if set.

company_name

company_name: str | None

The name of the company that owns this product, if set.

company

company: Company | None

The company that owns this product, if set.

This fetches the full record from Odoo once, and caches it for subsequent accesses.

default_code

default_code: str

The Default Code for this product.

In the OpenStack Integration add-on, this is used to store the rated unit for the service product.

description

description: str

A short description of this product.

display_name

display_name: str

The name of this product in OpenStack, and on invoices.

list_price

list_price: float

The list price of the product.

This becomes the unit price of the product on invoices.

name

name: str

The name of the product.

uom_id

uom_id: int

The ID for the Unit of Measure for this product.

uom_name

uom_name: str

The name of the Unit of Measure for this product.

uom

uom: Uom

The Unit of Measure for this product.

This fetches the full record from Odoo once, and caches it for subsequent accesses.