Skip to content

Pricings

albert.collections.pricings.PricingCollection

PricingCollection(*, session: AlbertSession)

Bases: BaseCollection

Manage Pricing entries for Inventory Items in the Albert platform.

A Pricing is a price entry for an Inventory Item (InventoryItem): a cost for a given amount of the material, recorded for a specific company and location. An item can have many pricings (for example, different suppliers, sites, or pack sizes), so pricings are usually retrieved by the inventory item they belong to rather than one at a time.

This collection is accessed as client.pricings.

Example

from albert import Albert

client = Albert()
pricings = client.pricings.get_by_inventory_id(inventory_id="INVA9999999")
for pricing in pricings:
    print(pricing.price, pricing.currency)

Parameters:

Name Type Description Default
session AlbertSession

The authenticated Albert session used for API calls.

required

Attributes:

Name Type Description
base_path str

The base API route for pricing requests.

Methods:

Name Description
create

Create a new pricing entry for an inventory item.

get_by_id

Get a single pricing by its ID.

get_by_inventory_id

Get the pricings for one inventory item, optionally grouped/filtered.

get_by_inventory_ids

Get pricings for several inventory items at once.

update

Update an existing pricing.

delete

Delete a pricing by its ID.

Parameters:

Name Type Description Default
session AlbertSession

The authenticated Albert session used for API calls.

required
Source code in src/albert/collections/pricings.py
def __init__(self, *, session: AlbertSession):
    """Initialize a PricingCollection.

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

base_path

base_path = (
    f"/api/{PricingCollection._api_version}/pricings"
)

create

create(*, pricing: Pricing) -> Pricing

Create a new pricing entry for an inventory item.

Example

from albert.resources.pricings import Pricing
from albert.resources.companies import Company
from albert.resources.locations import Location

pricing = Pricing(
    inventory_id="INVA9999999",
    company=Company(name="Acme Chemicals"),
    location=Location(name="Pittsburgh"),
    price=12.50,
)
created = client.pricings.create(pricing=pricing)
created.id

Parameters:

Name Type Description Default
pricing Pricing

The pricing to create. inventory_id, company, location, and price identify the item, source, site, and cost; see Pricing. default cannot be set on create; use update.

required

Returns:

Type Description
Pricing

The newly created pricing, populated with its assigned ID.

Source code in src/albert/collections/pricings.py
def create(self, *, pricing: Pricing) -> Pricing:
    """Create a new pricing entry for an inventory item.

    !!! example
        ```python
        from albert.resources.pricings import Pricing
        from albert.resources.companies import Company
        from albert.resources.locations import Location

        pricing = Pricing(
            inventory_id="INVA9999999",
            company=Company(name="Acme Chemicals"),
            location=Location(name="Pittsburgh"),
            price=12.50,
        )
        created = client.pricings.create(pricing=pricing)
        created.id
        ```

    Parameters
    ----------
    pricing : Pricing
        The pricing to create. ``inventory_id``, ``company``, ``location``, and
        ``price`` identify the item, source, site, and cost; see
        [`Pricing`][albert.resources.pricings.Pricing]. ``default`` cannot be
        set on create; use [`update`][albert.collections.pricings.PricingCollection.update].

    Returns
    -------
    Pricing
        The newly created pricing, populated with its assigned ID.
    """
    payload = pricing.model_dump(
        by_alias=True,
        exclude_none=True,
        mode="json",
        exclude={"default"},
    )
    response = self.session.post(self.base_path, json=payload)
    return Pricing(**response.json())

get_by_id

get_by_id(*, id: str) -> Pricing

Get a single pricing by its ID.

Example

pricing = client.pricings.get_by_id(id="...")
pricing.price

Parameters:

Name Type Description Default
id str

The ID of the pricing to retrieve.

required

Returns:

Type Description
Pricing

The fully populated pricing.

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

    !!! example
        ```python
        pricing = client.pricings.get_by_id(id="...")
        pricing.price
        ```

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

    Returns
    -------
    Pricing
        The fully populated pricing.
    """
    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: InventoryId,
    group_by: PricingBy | None = None,
    filter_by: PricingBy | None = None,
    filter_id: str | None = None,
    order_by: OrderBy | None = None,
) -> list[Pricing]

Get the pricings for a single inventory item.

Returns every pricing entry attached to the given inventory item, with optional grouping, filtering, and sorting. To pull pricings for many items at once, use get_by_inventory_ids.

Example

pricings = client.pricings.get_by_inventory_id(inventory_id="INVA9999999")
[p.price for p in pricings]

Parameters:

Name Type Description Default
inventory_id str

The Inventory ID to retrieve pricings for (format INV...).

required
group_by PricingBy

Group the results by company or location. See PricingBy.

None
filter_by PricingBy

The dimension (company or location) to filter on. Pair with filter_id.

None
filter_id str

The ID to match on the filter_by dimension.

None
order_by OrderBy

Sort direction for the results.

None

Returns:

Type Description
list[Pricing]

The pricings for the item matching the provided parameters.

Source code in src/albert/collections/pricings.py
@validate_call
def get_by_inventory_id(
    self,
    *,
    inventory_id: InventoryId,
    group_by: PricingBy | None = None,
    filter_by: PricingBy | None = None,
    filter_id: str | None = None,
    order_by: OrderBy | None = None,
) -> list[Pricing]:
    """Get the pricings for a single inventory item.

    Returns every pricing entry attached to the given inventory item, with
    optional grouping, filtering, and sorting. To pull pricings for many items
    at once, use [`get_by_inventory_ids`][albert.collections.pricings.PricingCollection.get_by_inventory_ids].

    !!! example
        ```python
        pricings = client.pricings.get_by_inventory_id(inventory_id="INVA9999999")
        [p.price for p in pricings]
        ```

    Parameters
    ----------
    inventory_id : str
        The Inventory ID to retrieve pricings for (format ``INV...``).
    group_by : PricingBy, optional
        Group the results by company or location. See
        [`PricingBy`][albert.resources.pricings.PricingBy].
    filter_by : PricingBy, optional
        The dimension (company or location) to filter on. Pair with
        ``filter_id``.
    filter_id : str, optional
        The ID to match on the ``filter_by`` dimension.
    order_by : OrderBy, optional
        Sort direction for the results.

    Returns
    -------
    list[Pricing]
        The pricings for the item 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]

Get pricings for several inventory items at once.

Each returned InventoryPricings groups one item's pricings under its inventory ID.

Example

grouped = client.pricings.get_by_inventory_ids(
    inventory_ids=["INVA9999999", "INVA9999998"]
)
grouped[0].pricings

Parameters:

Name Type Description Default
inventory_ids list[str]

The Inventory IDs to retrieve pricings for (format INV...).

required

Returns:

Type Description
list[InventoryPricings]

One entry per item, each holding that item's pricings.

Source code in src/albert/collections/pricings.py
@validate_call
def get_by_inventory_ids(self, *, inventory_ids: list[InventoryId]) -> list[InventoryPricings]:
    """Get pricings for several inventory items at once.

    Each returned [`InventoryPricings`][albert.resources.pricings.InventoryPricings] groups
    one item's pricings under its inventory ID.

    !!! example
        ```python
        grouped = client.pricings.get_by_inventory_ids(
            inventory_ids=["INVA9999999", "INVA9999998"]
        )
        grouped[0].pricings
        ```

    Parameters
    ----------
    inventory_ids : list[str]
        The Inventory IDs to retrieve pricings for (format ``INV...``).

    Returns
    -------
    list[InventoryPricings]
        One entry per item, each holding that item's pricings.
    """
    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

Delete a pricing by its ID.

Example

client.pricings.delete(id="...")

Parameters:

Name Type Description Default
id str

The ID of the pricing to delete.

required

Returns:

Type Description
None
Source code in src/albert/collections/pricings.py
@validate_call
def delete(self, *, id: str) -> None:
    """Delete a pricing by its ID.

    !!! example
        ```python
        client.pricings.delete(id="...")
        ```

    Parameters
    ----------
    id : str
        The ID of the pricing to delete.

    Returns
    -------
    None
    """
    url = f"{self.base_path}/{id}"
    self.session.delete(url)

update

update(*, pricing: Pricing) -> Pricing

Update an existing pricing.

Fetch the pricing (e.g. with get_by_id), modify the updatable fields on the returned object, then pass it here. The company and location links can also be reassigned.

Example

pricing = client.pricings.get_by_id(id="...")
pricing.price = 15.00
updated = client.pricings.update(pricing=pricing)
updated.price
# 15.0

Parameters:

Name Type Description Default
pricing Pricing

The pricing to update. Must have a valid id.

required

Returns:

Type Description
Pricing

The updated pricing as it appears in Albert.

Notes

The following fields can be updated: currency, default, description, expiration_date, fob, inventory_id, lead_time, lead_time_unit, pack_size, price.

default must be 0 (not default) or 1 (default). Can only be set via update, not on create.

Source code in src/albert/collections/pricings.py
def update(self, *, pricing: Pricing) -> Pricing:
    """Update an existing pricing.

    Fetch the pricing (e.g. with [`get_by_id`][albert.collections.pricings.PricingCollection.get_by_id]), modify the updatable
    fields on the returned object, then pass it here. The ``company`` and
    ``location`` links can also be reassigned.

    !!! example
        ```python
        pricing = client.pricings.get_by_id(id="...")
        pricing.price = 15.00
        updated = client.pricings.update(pricing=pricing)
        updated.price
        # 15.0
        ```

    Parameters
    ----------
    pricing : Pricing
        The pricing to update. Must have a valid ``id``.

    Returns
    -------
    Pricing
        The updated pricing as it appears in Albert.

    Notes
    -----
    The following fields can be updated: ``currency``, ``default``,
    ``description``, ``expiration_date``, ``fob``, ``inventory_id``,
    ``lead_time``, ``lead_time_unit``, ``pack_size``, ``price``.

    ``default`` must be ``0`` (not default) or ``1`` (default). Can only be
    set via update, not on create.
    """
    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)