Lots
albert.collections.lots.LotCollection
Bases: BaseCollection
Manage Lots in the Albert platform.
A Lot is a specific physical batch or quantity of an Inventory Item, for
example a received shipment or a produced amount. Each lot tracks
lot-specific details such as how much is currently on hand, where it is
stored, its cost, and who owns it. Every lot belongs to exactly one
Inventory Item (its parent), referenced by the parent Inventory ID
(format INV...); a lot's own ID has the format LOT....
Lots are referenced throughout property data: a lot_id scopes results to
a specific physical batch. Some lots are produced by a Task and carry a
task_id linking them back to that Task.
Inventory Items themselves are managed through the Inventory collection
(InventoryCollection).
This collection is accessed as client.lots.
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 lot requests. |
Methods:
| Name | Description |
|---|---|
create |
Create one or more new lots. |
get_by_id |
Get a single lot by its ID. |
get_by_ids |
Get many lots by their IDs. |
search |
Fast, lightweight search returning partial lots (best for lookups/counts). |
get_all |
Return fully populated lots matching the given filters. |
adjust |
Adjust a lot's inventory on hand (add, subtract, set, or zero). |
transfer |
Move some or all of a lot's quantity to another storage location. |
update |
Update an existing lot. |
update_many |
Update multiple lots, for the subset of fields listed in its Notes. |
delete |
Delete a lot by its ID. |
delete_many |
Delete multiple lots by their IDs. |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
AlbertSession
|
The authenticated Albert session used for API calls. |
required |
Source code in src/albert/collections/lots.py
create
Create one or more new lots.
Use this to register physical batches against an existing Inventory Item
(each lot's inventory_id must point at its parent item). Both regular
lots and Task-produced lots can be created here.
Example
from albert import Albert
from albert.core.shared.models.base import EntityLink
from albert.resources.lots import Lot
client = Albert()
new_lot = Lot(
inventory_id="INVA9999999",
storage_location=EntityLink(id="STL9999999"),
initial_quantity=10.0,
inventory_on_hand=10.0,
cost=50.0,
manufacturer_lot_number="MLN-001",
)
created = client.lots.create(lots=[new_lot])
created[0].id
# 'LOTA1'
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lots
|
list[Lot]
|
The lots to create. Each lot requires |
required |
Returns:
| Type | Description |
|---|---|
list[Lot]
|
The created lots, each populated with its assigned Lot ID. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a regular lot is missing |
Notes
The SDK validates storage_location, initial_quantity, and
location (task lots) before POST. cost and
manufacturer_lot_number are enforced by the API for RawMaterials
parents but are not yet checked in the SDK. For volume-based lots,
callers must still supply mass initial_quantity and inventory_on_hand;
litres are not automatically derived from mass or density. See field
docstrings on Lot for the full create matrix.
notes and workflow_id are not saved on create. Assign a workflow
after creation via update;
lot notes are managed through the Notes collection
(NotesCollection).
If the API reports a partial success (some lots failed to create), a warning is logged and only the successfully created lots are returned.
Source code in src/albert/collections/lots.py
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 | |
get_by_id
Get a single, fully populated lot by its ID.
To retrieve many lots at once, use get_by_ids. To find lots
without knowing their IDs, use search or get_all.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
LotId
|
The Lot ID to retrieve (format |
required |
Returns:
| Type | Description |
|---|---|
Lot
|
The fully populated lot. |
Source code in src/albert/collections/lots.py
get_by_ids
Get many fully populated lots by their IDs.
Use this instead of repeated get_by_id calls when you already
have several Lot IDs to fetch. Arbitrarily long ID lists are supported.
Lots not found are omitted from the result.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ids
|
list[LotId]
|
The Lot IDs to retrieve (format |
required |
Returns:
| Type | Description |
|---|---|
list[Lot]
|
The lots matching the provided IDs. Order is not guaranteed to match the input list. |
Source code in src/albert/collections/lots.py
delete
delete(*, id: LotId) -> None
Delete a lot by its ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
LotId
|
The Lot ID to delete (format |
required |
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in src/albert/collections/lots.py
delete_many
Delete multiple lots by their IDs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ids
|
list[LotId]
|
The Lot IDs to delete (format |
required |
Returns:
| Type | Description |
|---|---|
None
|
|
Notes
At most five lots can be deleted at a time. If a failure occurs partway through a longer list, earlier deletions are not rolled back and the remaining lots are not attempted.
Source code in src/albert/collections/lots.py
search
search(
*,
text: str | None = None,
inventory_id: InventoryId
| list[InventoryId]
| None = None,
location_id: str | list[str] | None = None,
storage_location_id: str | list[str] | None = None,
task_id: TaskId | list[TaskId] | None = None,
category: InventoryCategory
| str
| list[InventoryCategory | str]
| None = None,
external_barcode_id: str | list[str] | None = None,
search_field: str | list[str] | None = None,
source_field: str | list[str] | None = None,
additional_field: str | list[str] | None = None,
contains_field: list[str] | None = None,
contains_text: list[str] | None = None,
created_by: list[str] | None = None,
custom_fields: dict[str, Any] | None = None,
facet_field: str | None = None,
facet_text: str | None = None,
inventory: list[str] | None = None,
location: list[str] | None = None,
storage_location: list[str] | None = None,
metadata_filters: dict[str, Any] | None = None,
owner: list[str] | None = None,
status: list[str] | None = None,
to_expiration_date: str | None = None,
from_on_hand: float | None = None,
is_drop_down: bool | None = None,
order_by: OrderBy = DESCENDING,
sort_by: str | None = None,
offset: int | None = None,
max_items: int | None = None,
) -> Iterator[LotSearchItem]
Search for lots matching the given filters.
This is the fast way to look up lots or count matches. It returns partial
(unhydrated) lots (LotSearchItem) rather
than full ones, so it is well suited to lookups. When you need every field
of each lot, use get_all instead, or hydrate individual results.
All filters are optional and combined together (AND). With no filters, all lots are returned.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Free-text query matched against lot fields. Truncated to 50 characters. |
None
|
inventory_id
|
InventoryId or list[InventoryId]
|
Filter by parent Inventory ID(s) (format |
None
|
location_id
|
str or list[str]
|
Filter by location ID(s). |
None
|
storage_location_id
|
str or list[str]
|
Filter by storage location ID(s) (format |
None
|
task_id
|
TaskId or list[TaskId]
|
Filter by the source Task ID(s) that produced the lots. |
None
|
category
|
InventoryCategory or list[str]
|
Filter by the parent inventory category (e.g. |
None
|
external_barcode_id
|
str or list[str]
|
Filter by external barcode ID(s). |
None
|
search_field
|
str or list[str]
|
Restrict which fields the |
None
|
source_field
|
str or list[str]
|
Restrict which fields are returned in the response. |
None
|
additional_field
|
str or list[str]
|
Request additional columns from the search index. |
None
|
contains_field
|
list[str]
|
Fields to search inside. |
None
|
contains_text
|
list[str]
|
Values to search for within |
None
|
created_by
|
list[str]
|
Filter by creator display name(s) or UserId(s). |
None
|
custom_fields
|
dict[str, Any]
|
Filter by custom field values. |
None
|
facet_field
|
str
|
Facet field to filter on. |
None
|
facet_text
|
str
|
Facet text to search for. |
None
|
inventory
|
list[str]
|
Filter by parent inventory name(s). |
None
|
location
|
list[str]
|
Filter by location name(s). |
None
|
storage_location
|
list[str]
|
Filter by storage location name(s). |
None
|
metadata_filters
|
dict[str, Any]
|
Filter by custom field (metadata) values. Keys are custom field names.
For string-type custom fields, map the name to a list of values, e.g.
|
None
|
owner
|
list[str]
|
Filter by lot owner display name(s) or UserId(s). |
None
|
status
|
list[str]
|
Filter by lot status values. |
None
|
to_expiration_date
|
str
|
Only include lots expiring on or before this date (ISO 8601). |
None
|
from_on_hand
|
float
|
Only include lots with inventory on hand strictly greater than this
value. Pass |
None
|
is_drop_down
|
bool
|
Apply dropdown sanitization to the search text when True. |
None
|
order_by
|
OrderBy
|
Sort direction for the results. Defaults to |
DESCENDING
|
sort_by
|
str
|
Attribute to sort by. |
None
|
max_items
|
int
|
Maximum number of lots to return in total. If None, returns all matching lots. |
None
|
Returns:
| Type | Description |
|---|---|
Iterator[LotSearchItem]
|
An iterator over matching partial (unhydrated) lots. |
Source code in src/albert/collections/lots.py
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 | |
get_all
get_all(
*,
parent_id: InventoryId | None = None,
inventory_id: InventoryId | None = None,
barcode_id: str | None = None,
parent_id_category: str | None = None,
inventory_on_hand: InventoryOnHandFilter | None = None,
location_id: str | None = None,
exact_match: bool = False,
begins_with: bool = False,
start_key: str | None = None,
max_items: int | None = None,
) -> Iterator[Lot]
Get fully populated lots matching the given filters.
Same purpose as search, but returns fully populated
Lot objects (every field populated), which
is slower. Use search when a lightweight result is enough.
All filters are optional and combined together (AND). A common use is
passing parent_id to list every lot of one Inventory Item.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parent_id
|
InventoryId
|
Fetch lots whose parent is this Inventory ID (format |
None
|
inventory_id
|
InventoryId
|
Fetch lots for the given inventory ID. |
None
|
barcode_id
|
str
|
Fetch lots with the given barcode ID. |
None
|
parent_id_category
|
str
|
Filter by the parent inventory category (e.g. |
None
|
inventory_on_hand
|
InventoryOnHandFilter
|
Filter by inventory on hand relative to zero. Requires |
None
|
location_id
|
str
|
Filter by location ID. |
None
|
exact_match
|
bool
|
Match |
False
|
begins_with
|
bool
|
Match |
False
|
start_key
|
str
|
Pagination key to continue listing from. |
None
|
max_items
|
int
|
Maximum number of lots to return in total. If None, returns all matching lots. |
None
|
Returns:
| Type | Description |
|---|---|
Iterator[Lot]
|
An iterator over the fully populated lots matching the filters. |
Source code in src/albert/collections/lots.py
567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 | |
adjust
adjust(
*,
lot_id: LotId,
action: LotAdjustmentAction,
quantity: float | None = None,
description: str | None = None,
) -> Lot
Adjust a lot's inventory on hand.
Use this to change how much of a lot is currently in stock, for example
to record consumption, restocking, or a physical recount. To move
quantity to a different storage location instead, use transfer.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lot_id
|
LotId
|
The lot to adjust (format |
required |
action
|
LotAdjustmentAction
|
How to apply
|
required |
quantity
|
float
|
The amount to apply. Required and must be greater than zero for
|
None
|
description
|
str
|
Free-text note recorded with the adjustment. |
None
|
Returns:
| Type | Description |
|---|---|
Lot
|
The refreshed lot after the adjustment. |
Notes
For volume-based lots, quantity is always expressed in mass units.
The server automatically recalculates inventory_on_hand_l using the
lot's locked density.
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/albert/collections/lots.py
748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 | |
transfer
transfer(
*,
lot_id: LotId,
quantity: float | Literal["ALL"],
storage_location_id: StorageLocationId,
owner: UserId | None = None,
) -> Lot
Transfer some or all of a lot's quantity to another storage location.
Use this to physically relocate stock. Transferring "ALL" simply
moves the source lot to the new storage location. Transferring a partial
amount splits the source lot: the requested quantity is removed from the
source and a new lot is created at the destination.
To change how much is in stock (rather than where it is), use
adjust.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lot_id
|
LotId
|
The source lot to transfer from (format |
required |
quantity
|
float or Literal['ALL']
|
The amount to transfer, or |
required |
storage_location_id
|
StorageLocationId
|
Destination storage location ID (format |
required |
owner
|
UserId
|
User ID (format |
None
|
Returns:
| Type | Description |
|---|---|
Lot
|
The updated source lot for an |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a numeric |
Warns:
| Type | Description |
|---|---|
UserWarning
|
If |
Source code in src/albert/collections/lots.py
848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 | |
update
Update an existing lot.
Fetch the lot (e.g. with get_by_id), modify the updatable fields
on the returned object, then pass it here. Only the fields listed in Notes
are applied. The lot is matched by its id.
For quantity changes, prefer adjust; for relocations, prefer
transfer. Both handle the inventory-on-hand bookkeeping for you.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lot
|
Lot
|
The lot carrying the desired changes. Its |
required |
Returns:
| Type | Description |
|---|---|
Lot
|
The refreshed lot after the update. |
Notes
The following fields can be updated: barcode_id, cost,
cost_l, expiration_date, external_barcode_id,
initial_quantity, inventory_on_hand, manufacturer_lot_number,
metadata, owner, pack_size, status, storage_location,
workflow_id.
density, initial_quantity_l, and inventory_on_hand_l are
fixed at creation and cannot be updated.
Clearing a field (setting it to None) is only supported for
expiration_date, pack_size, external_barcode_id, and
individual metadata keys; clearing any other field is rejected.
Source code in src/albert/collections/lots.py
update_many
Update multiple lots.
Each lot is changed to match the given state, and lots submitted without changes are left untouched. Only the fields listed in Notes can be changed this way; anything else raises ValueError rather than being silently dropped.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lots
|
list[Lot]
|
The lots carrying the desired changes. Each |
required |
notes
|
str
|
A note recorded against each changed lot. Defaults to "Bulk update". |
'Bulk update'
|
Returns:
| Type | Description |
|---|---|
list[Lot]
|
The refreshed lots. Order is not guaranteed to match the input list. |
Raises:
| Type | Description |
|---|---|
AlbertPartialError
|
If only some changes were applied. The error carries the applied
( |
NotFoundError
|
If a lot ID does not exist. |
ValueError
|
If a lot carries changes update_many cannot apply: an unsupported
field, a cleared field, a first-time |
Notes
The following fields can be updated: cost, expiration_date,
inventory_on_hand, status, storage_location. For any other
field, use update.
Unlike update, a field
cannot be cleared here; setting a field to None raises ValueError.
expiration_date can only be changed on lots that already have one,
and status can only be changed to active or quarantined (use
delete_many to
retire lots). One lot can carry at most four field changes.
If an error occurs partway through, earlier changes are not rolled back.
Source code in src/albert/collections/lots.py
1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 | |