Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/albert/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

__all__ = ["Albert", "AlbertClientCredentials", "AlbertSSOClient"]

__version__ = "1.6.5"
__version__ = "1.6.6"
33 changes: 32 additions & 1 deletion src/albert/collections/units.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from albert.core.session import AlbertSession
from albert.core.shared.enums import OrderBy, PaginationMode
from albert.core.shared.identifiers import UnitId
from albert.resources.units import Unit, UnitCategory
from albert.resources.units import MergeUnit, Unit, UnitCategory


class UnitCollection(BaseCollection):
Expand Down Expand Up @@ -245,3 +245,34 @@ def exists(self, *, name: str, exact_match: bool = True) -> bool:
True if the unit exists, False otherwise.
"""
return self.get_by_name(name=name, exact_match=exact_match) is not None

@validate_call
def merge(self, *, parent_id: UnitId, child_units: UnitId | list[UnitId]) -> None:
"""
Merge one or multiple child unit into a parent unit item.

Parameters
----------
parent_id : UnitId
The ID of the parent unit item.
child_units : UnitId | list[UnitId]
The ID(s) of the child unit item(s).

Returns
-------
None
"""

# define merge endpoint
url = f"{self.base_path}/merge"

if isinstance(child_units, list):
child_inventories = [{"id": i} for i in child_units]
else:
child_inventories = [{"id": child_units}]

# define payload using the class
payload = MergeUnit(parent_id=parent_id, child_inventories=child_inventories)

# post request
self.session.post(url, json=payload.model_dump(mode="json", by_alias=True))
6 changes: 6 additions & 0 deletions src/albert/resources/units.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from pydantic import Field

from albert.core.base import BaseAlbertModel
from albert.core.shared.identifiers import UnitId
from albert.core.shared.models.base import BaseResource


Expand Down Expand Up @@ -108,3 +110,7 @@ class Unit(BaseResource):

# Read-only fields
verified: bool | None = Field(default=False, exclude=True, frozen=True)

class MergeUnit(BaseAlbertModel):
parent_id: UnitId = Field(alias="parentId")
child_units: list[dict[str, UnitId]] = Field(alias="ChildUnits")