Stock Items Service
The `StockItemsService` is your primary tool for interacting with `StockItem` records. It provides a comprehensive set of methods for managing stock items, including retrieval, creation, updates, and handling file attachments.
Importing Helpers
To create and query stock items, you will need the `StockItemBuilder` and other query helpers.
from easy_acumatica.models.stock_item_builder import StockItemBuilder
from easy_acumatica.models.query_builder import QueryOptions
from easy_acumatica.models.filter_builder import F
CRUD Methods
get_stock_items(api_version, options=None)
Retrieves a list of stock items. Use `QueryOptions` to filter, select, and expand the results.
# Create a filter for active, finished good items
opts = QueryOptions(
filter=(F.ItemStatus == 'Active') & (F.ItemClass.ID == 'FINISHGOOD'),
select="InventoryID,Description,ItemClass",
expand="ItemClass"
)
# Fetch the stock items
active_items = client.stock_items.get_stock_items("24.200.001", options=opts)
get_stock_item_by_id(api_version, inventory_id, ...)
Retrieves a single, complete stock item record by its `InventoryID`.
# The InventoryID of the item to fetch
item_id = "STK-ITEM-01"
# Fetch the item
item = client.stock_items.get_stock_item_by_id("24.200.001", item_id)
create_stock_item(api_version, builder, ...)
Creates a new stock item using a `StockItemBuilder` instance to define its properties.
# Build the stock item payload
item_payload = (
StockItemBuilder()
.inventory_id("NEW-ITEM-001")
.description("New Test Stock Item")
.item_class("DEFAULT")
.base_uom("EACH")
)
# Create the stock item
new_item = client.stock_items.create_stock_item("24.200.001", builder=item_payload)
update_stock_item(api_version, builder, ...)
Updates an existing stock item. You must include the `InventoryID` in the builder to identify the record.
# Build the update payload
update_payload = (
StockItemBuilder()
.inventory_id("NEW-ITEM-001") # The item to update
.description("Updated Item Description")
)
# Update the stock item
updated_item = client.stock_items.update_stock_item(
"24.200.001",
builder=update_payload
)
Working with Attachments
get_stock_item_attachments(api_version, inventory_id)
This helper method retrieves a list of all file attachments for a specific stock item. It returns metadata about the files, not the file content itself.
item_id_with_files = "STK-ITEM-01"
attachments = client.stock_items.get_stock_item_attachments(
"24.200.001",
item_id_with_files
)
if attachments:
print(f"Attachments for {item_id_with_files}:")
for file in attachments:
print(f" - {file['name']}")