Skip to content

Pricings

albert.collections.pricings.PricingCollection

PricingCollection(*, session: AlbertSession)

Bases: BaseCollection

PricingCollection is a collection class for managing Pricing entities in the Albert platform.

Parameters:

Name Type Description Default
session AlbertSession

The Albert session instance.

required

Methods:

Name Description
create

Creates a new Pricing entity.

get_by_id

Retrieves a Pricing entity by its ID.

get_by_inventory_id

Returns a list of Pricing entities for the given inventory ID as per the provided parameters.

get_by_inventory_ids

Returns a list of Pricing resources for each parent inventory ID.

delete

Deletes a Pricing entity by its ID.

update

Updates a Pricing entity.

Attributes:

Name Type Description
base_path
Source code in src/albert/collections/pricings.py
def __init__(self, *, session: AlbertSession):
    """Initializes the PricingCollection with the provided session.

    Parameters
    ----------
    session : AlbertSession
        The Albert session instance.
    """
    super().__init__(session=session)
    self.base_path = f"/api/{PricingCollection._api_version}/pricings"

base_path

base_path = f'/api/{_api_version}/pricings'

create

create(*, pricing: Pricing) -> Pricing

Creates a new Pricing entity.

Parameters:

Name Type Description Default
pricing Pricing

The Pricing entity to create.

required

Returns:

Type Description
Pricing

The created Pricing entity.

Source code in src/albert/collections/pricings.py
def create(self, *, pricing: Pricing) -> Pricing:
    """Creates a new Pricing entity.

    Parameters
    ----------
    pricing : Pricing
        The Pricing entity to create.

    Returns
    -------
    Pricing
        The created Pricing entity.
    """
    payload = pricing.model_dump(by_alias=True, exclude_none=True, mode="json")
    response = self.session.post(self.base_path, json=payload)
    return Pricing(**response.json())

get_by_id

get_by_id(*, id: str) -> Pricing

Retrieves a Pricing entity by its ID.

Parameters:

Name Type Description Default
id str

The ID of the Pricing entity to retrieve.

required

Returns:

Type Description
Pricing

The Pricing entity if found, None otherwise.

Source code in src/albert/collections/pricings.py
def get_by_id(self, *, id: str) -> Pricing:
    """Retrieves a Pricing entity by its ID.

    Parameters
    ----------
    id : str
        The ID of the Pricing entity to retrieve.

    Returns
    -------
    Pricing
        The Pricing entity if found, None otherwise.
    """
    url = f"{self.base_path}/{id}"
    response = self.session.get(url)
    return Pricing(**response.json())

get_by_inventory_id

get_by_inventory_id(
    *,
    inventory_id: str,
    group_by: PricingBy | None = None,
    filter_by: PricingBy | None = None,
    filter_id: str | None = None,
    order_by: OrderBy | None = None,
) -> list[Pricing]

Returns a list of Pricing entities for the given inventory ID as per the provided parameters.

Parameters:

Name Type Description Default
inventory_id str

The ID of the inventory to retrieve pricings for.

required
group_by PricingBy | None

Grouping by PricingBy, by default None

None
filter_by PricingBy | None

Filter by PricingBy, by default None

None
filter_id str | None

The string to use as the filter, by default None

None
order_by OrderBy | None

The order to sort the results by, by default None

None

Returns:

Type Description
list[Pricing]

A list of Pricing entities matching the provided parameters.

Source code in src/albert/collections/pricings.py
def get_by_inventory_id(
    self,
    *,
    inventory_id: str,
    group_by: PricingBy | None = None,
    filter_by: PricingBy | None = None,
    filter_id: str | None = None,
    order_by: OrderBy | None = None,
) -> list[Pricing]:
    """Returns a list of Pricing entities for the given inventory ID as per the provided parameters.

    Parameters
    ----------
    inventory_id : str
        The ID of the inventory to retrieve pricings for.
    group_by : PricingBy | None, optional
        Grouping by PricingBy, by default None
    filter_by : PricingBy | None, optional
        Filter by PricingBy, by default None
    filter_id : str | None, optional
        The string to use as the filter, by default None
    order_by : OrderBy | None, optional
        The order to sort the results by, by default None

    Returns
    -------
    list[Pricing]
        A list of Pricing entities matching the provided parameters.
    """
    params = {
        "parentId": inventory_id,
        "groupBy": group_by,
        "filterBy": filter_by,
        "id": filter_id,
        "orderBy": order_by,
    }
    params = {k: v for k, v in params.items() if v is not None}
    response = self.session.get(self.base_path, params=params)
    items = response.json().get("Items", [])
    return [Pricing(**x) for x in items]

get_by_inventory_ids

get_by_inventory_ids(
    *, inventory_ids: list[InventoryId]
) -> list[InventoryPricings]

Returns a list of Pricing resources for each parent inventory ID.

Parameters:

Name Type Description Default
inventory_ids list[str]

The list of inventory IDs to retrieve pricings for.

required

Returns:

Type Description
list[InventoryPricing]

A list of InventoryPricing objects matching the provided inventory.

Source code in src/albert/collections/pricings.py
@validate_call
def get_by_inventory_ids(self, *, inventory_ids: list[InventoryId]) -> list[InventoryPricings]:
    """Returns a list of Pricing resources for each parent inventory ID.

    Parameters
    ----------
    inventory_ids : list[str]
        The list of inventory IDs to retrieve pricings for.

    Returns
    -------
    list[InventoryPricing]
        A list of InventoryPricing objects matching the provided inventory.
    """
    params = {"id": inventory_ids}
    response = self.session.get(f"{self.base_path}/ids", params=params)
    return [InventoryPricings(**x) for x in response.json()["Items"]]

delete

delete(*, id: str) -> None

Deletes a Pricing entity by its ID.

Parameters:

Name Type Description Default
id str

The ID of the Pricing entity to delete.

required
Source code in src/albert/collections/pricings.py
def delete(self, *, id: str) -> None:
    """Deletes a Pricing entity by its ID.

    Parameters
    ----------
    id : str
        The ID of the Pricing entity to delete.
    """
    url = f"{self.base_path}/{id}"
    self.session.delete(url)

update

update(*, pricing: Pricing) -> Pricing

Updates a Pricing entity.

Parameters:

Name Type Description Default
pricing Pricing

The updated Pricing entity.

required

Returns:

Type Description
Pricing

The updated Pricing entity as it appears in Albert.

Source code in src/albert/collections/pricings.py
def update(self, *, pricing: Pricing) -> Pricing:
    """Updates a Pricing entity.

    Parameters
    ----------
    pricing : Pricing
        The updated Pricing entity.

    Returns
    -------
    Pricing
        The updated Pricing entity as it appears in Albert.
    """
    current_pricing = self.get_by_id(id=pricing.id)
    patch_payload = self._pricing_patch_payload(existing=current_pricing, updated=pricing)
    self.session.patch(
        url=f"{self.base_path}/{pricing.id}",
        json=patch_payload.model_dump(mode="json", by_alias=True),
    )
    return self.get_by_id(id=pricing.id)