From 5cd3767ab23fa74a13eabed09cd02d2687a6a6c2 Mon Sep 17 00:00:00 2001 From: m-j-hofmann <139861272+m-j-hofmann@users.noreply.github.com> Date: Fri, 26 Sep 2025 14:01:57 +0200 Subject: [PATCH 1/2] units merge added --- src/albert/collections/units.py | 33 ++++++++++++++++++++++++++++++++- src/albert/resources/units.py | 6 ++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/albert/collections/units.py b/src/albert/collections/units.py index 3a6e95a3..92b3a18a 100644 --- a/src/albert/collections/units.py +++ b/src/albert/collections/units.py @@ -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): @@ -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)) diff --git a/src/albert/resources/units.py b/src/albert/resources/units.py index 51a11ddb..ed4f5c85 100644 --- a/src/albert/resources/units.py +++ b/src/albert/resources/units.py @@ -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 @@ -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") From 3f998695bfcd701d0f9189f2aebf978ec39f98d0 Mon Sep 17 00:00:00 2001 From: m-j-hofmann <139861272+m-j-hofmann@users.noreply.github.com> Date: Fri, 26 Sep 2025 14:29:35 +0200 Subject: [PATCH 2/2] version bump --- src/albert/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/albert/__init__.py b/src/albert/__init__.py index de58ed13..a2a2f481 100644 --- a/src/albert/__init__.py +++ b/src/albert/__init__.py @@ -4,4 +4,4 @@ __all__ = ["Albert", "AlbertClientCredentials", "AlbertSSOClient"] -__version__ = "1.6.5" +__version__ = "1.6.6"