pub struct Inventory { /* private fields */ }Expand description
Inventory operations interface.
Implementations§
Source§impl Inventory
impl Inventory
Sourcepub fn create_item(&self, input: CreateInventoryItem) -> Result<InventoryItem>
pub fn create_item(&self, input: CreateInventoryItem) -> Result<InventoryItem>
Create a new inventory item (SKU).
§Example
commerce.inventory().create_item(CreateInventoryItem {
sku: "SKU-001".into(),
name: "Widget".into(),
initial_quantity: Some(dec!(100)),
reorder_point: Some(dec!(10)),
..Default::default()
})?;Sourcepub fn get_item_by_sku(&self, sku: &str) -> Result<Option<InventoryItem>>
pub fn get_item_by_sku(&self, sku: &str) -> Result<Option<InventoryItem>>
Get an inventory item by SKU.
Sourcepub fn get_stock(&self, sku: &str) -> Result<Option<StockLevel>>
pub fn get_stock(&self, sku: &str) -> Result<Option<StockLevel>>
Get stock level for a SKU (aggregated across all locations).
§Example
if let Some(stock) = commerce.inventory().get_stock("SKU-001")? {
println!("Available: {}", stock.total_available);
for loc in stock.locations {
println!(" Location {}: {}", loc.location_id, loc.available);
}
}Sourcepub fn adjust(
&self,
sku: &str,
quantity: Decimal,
reason: &str,
) -> Result<InventoryTransaction>
pub fn adjust( &self, sku: &str, quantity: Decimal, reason: &str, ) -> Result<InventoryTransaction>
Adjust inventory quantity.
Use positive numbers to add stock, negative to remove.
§Example
// Add 50 units
commerce.inventory().adjust("SKU-001", dec!(50), "Restocked from supplier")?;
// Remove 5 units
commerce.inventory().adjust("SKU-001", dec!(-5), "Damaged items")?;Sourcepub fn adjust_at_location(
&self,
sku: &str,
location_id: i32,
quantity: Decimal,
reason: &str,
) -> Result<InventoryTransaction>
pub fn adjust_at_location( &self, sku: &str, location_id: i32, quantity: Decimal, reason: &str, ) -> Result<InventoryTransaction>
Adjust inventory at a specific location.
Sourcepub fn reserve(
&self,
sku: &str,
quantity: Decimal,
reference_type: &str,
reference_id: &str,
expires_in_seconds: Option<i64>,
) -> Result<InventoryReservation>
pub fn reserve( &self, sku: &str, quantity: Decimal, reference_type: &str, reference_id: &str, expires_in_seconds: Option<i64>, ) -> Result<InventoryReservation>
Reserve inventory for an order or other reference.
§Example
let reservation = commerce.inventory().reserve(
"SKU-001",
dec!(5),
"order",
"ord_12345",
Some(3600), // Expires in 1 hour
)?;Sourcepub fn release_reservation(&self, reservation_id: Uuid) -> Result<()>
pub fn release_reservation(&self, reservation_id: Uuid) -> Result<()>
Release a reservation.
Sourcepub fn confirm_reservation(&self, reservation_id: Uuid) -> Result<()>
pub fn confirm_reservation(&self, reservation_id: Uuid) -> Result<()>
Confirm a reservation (marks as allocated).
Sourcepub fn list_reservations_by_reference(
&self,
reference_type: &str,
reference_id: &str,
) -> Result<Vec<InventoryReservation>>
pub fn list_reservations_by_reference( &self, reference_type: &str, reference_id: &str, ) -> Result<Vec<InventoryReservation>>
List reservations by reference (e.g., order id).
Sourcepub fn list(&self, filter: InventoryFilter) -> Result<Vec<InventoryItem>>
pub fn list(&self, filter: InventoryFilter) -> Result<Vec<InventoryItem>>
List inventory items with optional filtering.
Sourcepub fn get_reorder_needed(&self) -> Result<Vec<StockLevel>>
pub fn get_reorder_needed(&self) -> Result<Vec<StockLevel>>
Get items that need reordering (below reorder point).
Sourcepub fn get_transactions(
&self,
item_id: i64,
limit: u32,
) -> Result<Vec<InventoryTransaction>>
pub fn get_transactions( &self, item_id: i64, limit: u32, ) -> Result<Vec<InventoryTransaction>>
Get transaction history for an item.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Inventory
impl !UnwindSafe for Inventory
impl Freeze for Inventory
impl Send for Inventory
impl Sync for Inventory
impl Unpin for Inventory
impl UnsafeUnpin for Inventory
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more