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:
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
¶
The ID for the category this product is under.
categ_name
¶
The name of the category this product is under.
categ
¶
The category this product is under.
This fetches the full record from Odoo once, and caches it for subsequent accesses.
company_id
¶
The ID for the company that owns this product, if set.
company_name
¶
The name of the company that owns this product, if set.
company
¶
The company that owns this product, if set.
This fetches the full record from Odoo once, and caches it for subsequent accesses.
default_code
¶
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
¶
A short description of this product.
display_name
¶
The name of this product in OpenStack, and on invoices.
list_price
¶
The list price of the product.
This becomes the unit price of the product on invoices.
name
¶
The name of the product.
uom_id
¶
The ID for the Unit of Measure for this product.
uom_name
¶
The name of the Unit of Measure for this product.
uom
¶
The Unit of Measure for this product.
This fetches the full record from Odoo once, and caches it for subsequent accesses.