Skip to main content

Inventory

Struct Inventory 

Source
pub struct Inventory { /* private fields */ }
Expand description

Inventory operations interface.

Implementations§

Source§

impl Inventory

Source

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()
})?;
Source

pub fn get_item(&self, id: i64) -> Result<Option<InventoryItem>>

Get an inventory item by ID.

Source

pub fn get_item_by_sku(&self, sku: &str) -> Result<Option<InventoryItem>>

Get an inventory item by SKU.

Source

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);
    }
}
Source

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")?;
Source

pub fn adjust_at_location( &self, sku: &str, location_id: i32, quantity: Decimal, reason: &str, ) -> Result<InventoryTransaction>

Adjust inventory at a specific location.

Source

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
)?;
Source

pub fn release_reservation(&self, reservation_id: Uuid) -> Result<()>

Release a reservation.

Source

pub fn confirm_reservation(&self, reservation_id: Uuid) -> Result<()>

Confirm a reservation (marks as allocated).

Source

pub fn list_reservations_by_reference( &self, reference_type: &str, reference_id: &str, ) -> Result<Vec<InventoryReservation>>

List reservations by reference (e.g., order id).

Source

pub fn list(&self, filter: InventoryFilter) -> Result<Vec<InventoryItem>>

List inventory items with optional filtering.

Source

pub fn get_reorder_needed(&self) -> Result<Vec<StockLevel>>

Get items that need reordering (below reorder point).

Source

pub fn get_transactions( &self, item_id: i64, limit: u32, ) -> Result<Vec<InventoryTransaction>>

Get transaction history for an item.

Source

pub fn has_stock(&self, sku: &str, quantity: Decimal) -> Result<bool>

Check if a SKU has sufficient available quantity.

Trait Implementations§

Source§

impl Debug for Inventory

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more