Companies
albert.collections.companies.CompanyCollection
Bases: BaseCollection
Manage Companies in the Albert platform.
A Company is a manufacturing company or supplier: the organization that makes
or supplies a material. Companies are the company linked on raw-material
inventory items (see InventoryItem), so
they are usually created as a side effect of registering raw materials, but
they can also be managed directly here.
Companies are identified by a Company ID (format COM...) and are looked up
primarily by name. Because a Company is essentially a name, this collection
offers find-or-create and rename helpers in addition to the usual CRUD.
This collection is accessed as client.companies.
Example
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 company requests. |
Methods:
| Name | Description |
|---|---|
get_all |
Iterate over companies, optionally filtered by name. |
get_by_id |
Get a single company by its ID. |
get_by_name |
Get a single company by name, or None if not found. |
exists |
Check whether a company with the given name exists. |
create |
Create a new company from a name or Company object. |
get_or_create |
Return the existing company with this name, or create it. |
rename |
Rename an existing company. |
update |
Update an existing company (identified by its ID). |
merge |
Merge one or more duplicate companies into a parent company. |
delete |
Delete a company 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/companies.py
get_all
get_all(
*,
name: str | list[str] = None,
exact_match: bool = True,
start_key: str | None = None,
max_items: int | None = None,
) -> Iterator[Company]
Iterate over companies, optionally filtered by name.
Use this to list companies or to find companies whose name matches a
search term. To fetch a single company, prefer get_by_id (by ID)
or get_by_name (by name).
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str or list[str]
|
One or more company names to filter by. When omitted, all companies are returned. |
None
|
exact_match
|
bool
|
When True (default), only companies whose name matches |
True
|
start_key
|
str
|
Pagination cursor to resume from a previous page. Usually left unset. |
None
|
max_items
|
int
|
Maximum number of companies to return in total. If None, iterates over all matching companies. |
None
|
Returns:
| Type | Description |
|---|---|
Iterator[Company]
|
An iterator over the matching |
Source code in src/albert/collections/companies.py
exists
Check whether a company with the given name exists.
Useful before creating a company to avoid duplicates. To get the matching
company itself, use get_by_name; to look up or create in one step,
use get_or_create.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The company name to check for. |
required |
exact_match
|
bool
|
When True (default), requires an exact name match. When False, matches on a substring of the name. |
True
|
Returns:
| Type | Description |
|---|---|
bool
|
True if a matching company exists, False otherwise. |
Source code in src/albert/collections/companies.py
get_by_id
Get a single company by its ID.
To look up a company when you only know its name, use get_by_name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
CompanyId
|
The Company ID (format |
required |
Returns:
| Type | Description |
|---|---|
Company
|
The fully populated |
Source code in src/albert/collections/companies.py
get_by_name
Get a single company by name.
Returns the first match, or None if no company matches. To check only for
existence, use exists; to look up or create in one step, use
get_or_create.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The company name to look up. |
required |
exact_match
|
bool
|
When True (default), requires an exact name match. When False, matches on a substring of the name. |
True
|
Returns:
| Type | Description |
|---|---|
Company or None
|
The matching |
Source code in src/albert/collections/companies.py
create
Create a new company.
To avoid creating a duplicate when a company with the same name may
already exist, use get_or_create instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
company
|
str or Company
|
The company to create. Pass a plain name string, or a
|
required |
Returns:
| Type | Description |
|---|---|
Company
|
The newly created company, populated with its assigned Company ID. |
Source code in src/albert/collections/companies.py
get_or_create
Return the existing company with this name, or create it if none exists.
A find-or-create helper: matches on exact name via get_by_name,
and falls back to create when there is no match. This is the safe
way to reference a company without risking a duplicate.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
company
|
str or Company
|
The company to look up or create. Pass a plain name string, or a
|
required |
Returns:
| Type | Description |
|---|---|
Company
|
The existing company if one matches by name, otherwise the newly created company. |
Source code in src/albert/collections/companies.py
merge
Merge one or more duplicate companies into a parent company.
Use this to consolidate duplicate companies: the child company records are folded into the parent, which is kept. Inventory items and other entities referencing a child are repointed to the parent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parent_id
|
CompanyId
|
The Company ID (format |
required |
child_ids
|
CompanyId or list[CompanyId]
|
One or more Company IDs of the duplicate companies to merge into the parent. |
required |
Returns:
| Type | Description |
|---|---|
Company
|
The parent company, re-fetched after the merge. |
Source code in src/albert/collections/companies.py
delete
delete(*, id: CompanyId) -> None
Delete a company by its ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
CompanyId
|
The Company ID (format |
required |
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in src/albert/collections/companies.py
rename
Rename an existing company, looking it up by its current name.
A convenience wrapper that finds the company by name and updates its name.
If you already hold a Company object,
you can instead set name and call update.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
old_name
|
str
|
The company's current name. Must match an existing company exactly. |
required |
new_name
|
str
|
The new name to assign. |
required |
Returns:
| Type | Description |
|---|---|
Company
|
The renamed company, re-fetched after the update. |
Raises:
| Type | Description |
|---|---|
AlbertException
|
If no company with |
Source code in src/albert/collections/companies.py
update
Update an existing company.
The company is identified by its id, which must be set. Only the
updatable fields listed in Notes are applied. To rename a company by its
current name rather than by its ID, use rename.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
company
|
Company
|
The company to update, carrying the desired field values. Its |
required |
Returns:
| Type | Description |
|---|---|
Company
|
The updated company. |
Notes
The following fields can be updated: name.