Skip to main content

WarehouseOps

Struct WarehouseOps 

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

Warehouse and Location management interface.

Implementations§

Source§

impl WarehouseOps

Source

pub fn create_warehouse(&self, input: CreateWarehouse) -> Result<Warehouse>

Create a new warehouse.

§Example
use stateset_embedded::{Commerce, CreateWarehouse, WarehouseType, WarehouseAddress};

let commerce = Commerce::new(":memory:")?;

let warehouse = commerce.warehouse().create_warehouse(CreateWarehouse {
    code: "DC-EAST".into(),
    name: "East Coast Distribution Center".into(),
    warehouse_type: WarehouseType::Distribution,
    address: WarehouseAddress {
        street1: "123 Logistics Way".into(),
        city: "Newark".into(),
        state: "NJ".into(),
        postal_code: "07102".into(),
        country: "US".into(),
        ..Default::default()
    },
    timezone: Some("America/New_York".into()),
})?;
Source

pub fn get_warehouse(&self, id: i32) -> Result<Option<Warehouse>>

Get a warehouse by ID.

Source

pub fn get_warehouse_by_code(&self, code: &str) -> Result<Option<Warehouse>>

Get a warehouse by code.

Source

pub fn update_warehouse( &self, id: i32, input: UpdateWarehouse, ) -> Result<Warehouse>

Update a warehouse.

Source

pub fn list_warehouses(&self, filter: WarehouseFilter) -> Result<Vec<Warehouse>>

List warehouses with optional filtering.

§Example
use stateset_embedded::{Commerce, WarehouseFilter, WarehouseType};

let commerce = Commerce::new(":memory:")?;

// Get all active distribution centers
let warehouses = commerce.warehouse().list_warehouses(WarehouseFilter {
    warehouse_type: Some(WarehouseType::Distribution),
    is_active: Some(true),
    ..Default::default()
})?;
Source

pub fn delete_warehouse(&self, id: i32) -> Result<()>

Delete a warehouse. Only warehouses without locations can be deleted.

Source

pub fn count_warehouses(&self, filter: WarehouseFilter) -> Result<u64>

Count warehouses matching the filter.

Source

pub fn create_zone(&self, input: CreateZone) -> Result<Zone>

Create a new zone within a warehouse.

Zones are logical groupings of locations (e.g., “Bulk Storage”, “Pick Area”, “Returns”).

Source

pub fn get_zone(&self, id: i32) -> Result<Option<Zone>>

Get a zone by ID.

Source

pub fn get_zones(&self, warehouse_id: i32) -> Result<Vec<Zone>>

Get all zones in a warehouse.

Source

pub fn update_zone(&self, id: i32, input: UpdateZone) -> Result<Zone>

Update a zone.

Source

pub fn delete_zone(&self, id: i32) -> Result<()>

Delete a zone.

Source

pub fn create_location(&self, input: CreateLocation) -> Result<Location>

Create a new location within a warehouse.

§Example
use stateset_embedded::{Commerce, CreateLocation, LocationType};
use rust_decimal_macros::dec;

let commerce = Commerce::new(":memory:")?;

// Create a pick location with capacity constraints
let location = commerce.warehouse().create_location(CreateLocation {
    warehouse_id: 1,
    location_type: LocationType::Pick,
    zone: Some("A".into()),
    aisle: Some("01".into()),
    rack: Some("05".into()),
    level: Some("2".into()),
    bin: Some("03".into()),
    max_weight_kg: Some(dec!(100)),
    max_volume_m3: Some(dec!(0.5)),
    is_pickable: Some(true),
    is_receivable: Some(false),
    ..Default::default()
})?;

println!("Created location: {}", location.code); // e.g., "A-01-05-2-03"
Source

pub fn get_location(&self, id: i32) -> Result<Option<Location>>

Get a location by ID.

Source

pub fn get_location_by_code( &self, warehouse_id: i32, code: &str, ) -> Result<Option<Location>>

Get a location by code within a warehouse.

Source

pub fn update_location( &self, id: i32, input: UpdateLocation, ) -> Result<Location>

Update a location.

Source

pub fn list_locations(&self, filter: LocationFilter) -> Result<Vec<Location>>

List locations with optional filtering.

§Example
use stateset_embedded::{Commerce, LocationFilter, LocationType};

let commerce = Commerce::new(":memory:")?;

// Get all pickable locations in zone A
let locations = commerce.warehouse().list_locations(LocationFilter {
    warehouse_id: Some(1),
    zone: Some("A".into()),
    is_pickable: Some(true),
    is_active: Some(true),
    ..Default::default()
})?;
Source

pub fn delete_location(&self, id: i32) -> Result<()>

Delete a location. Only locations without inventory can be deleted.

Source

pub fn count_locations(&self, filter: LocationFilter) -> Result<u64>

Count locations matching the filter.

Source

pub fn get_locations_for_warehouse( &self, warehouse_id: i32, ) -> Result<Vec<Location>>

Get all active locations for a warehouse.

Source

pub fn get_pickable_locations( &self, warehouse_id: i32, sku: &str, ) -> Result<Vec<Location>>

Get pickable locations with available inventory for a SKU.

Returns locations that are marked as pickable and have available (non-reserved) inventory for the specified SKU.

Source

pub fn get_receivable_locations( &self, warehouse_id: i32, ) -> Result<Vec<Location>>

Get receivable locations for a warehouse.

Returns locations where inventory can be received (e.g., receiving docks, staging areas).

Source

pub fn create_locations_batch( &self, inputs: Vec<CreateLocation>, ) -> Result<BatchResult<Location>>

Create multiple locations in a batch.

Returns a BatchResult with succeeded and failed operations.

Source

pub fn get_locations_batch(&self, ids: Vec<i32>) -> Result<Vec<Location>>

Get multiple locations by ID.

Source

pub fn get_location_inventory( &self, location_id: i32, ) -> Result<Vec<LocationInventory>>

Get all inventory at a specific location.

Source

pub fn get_inventory_for_sku( &self, warehouse_id: i32, sku: &str, ) -> Result<Vec<LocationInventory>>

Get all locations with inventory for a SKU within a warehouse.

Source

pub fn adjust_inventory( &self, input: AdjustLocationInventory, ) -> Result<LocationInventory>

Adjust inventory at a location.

Use positive quantities to add inventory, negative to remove. Creates a movement record for audit trail.

§Example
use stateset_embedded::{Commerce, AdjustLocationInventory};
use rust_decimal_macros::dec;

let commerce = Commerce::new(":memory:")?;

// Add inventory from receiving
let inventory = commerce.warehouse().adjust_inventory(AdjustLocationInventory {
    location_id: 1,
    sku: "PROD-001".into(),
    lot_id: None,
    quantity: dec!(100),
    reason: "Receipt from PO-12345".into(),
    reference_type: Some("purchase_order".into()),
    reference_id: None,
    performed_by: Some("warehouse_user".into()),
})?;

println!("New quantity on hand: {}", inventory.quantity_on_hand);
Source

pub fn move_inventory(&self, input: MoveInventory) -> Result<LocationMovement>

Move inventory between locations.

Validates that sufficient available (non-reserved) quantity exists at the source location. Creates movement records for both locations.

§Example
use stateset_embedded::{Commerce, MoveInventory};
use rust_decimal_macros::dec;

let commerce = Commerce::new(":memory:")?;

// Move inventory from bulk to pick location
let movement = commerce.warehouse().move_inventory(MoveInventory {
    from_location_id: 1,  // Bulk storage
    to_location_id: 2,    // Pick location
    sku: "PROD-001".into(),
    lot_id: None,
    quantity: dec!(50),
    reason: Some("Replenish pick location".into()),
    performed_by: Some("forklift_operator".into()),
})?;
Source

pub fn list_location_inventory( &self, filter: LocationInventoryFilter, ) -> Result<Vec<LocationInventory>>

List location inventory with optional filtering.

Source

pub fn get_total_available( &self, warehouse_id: i32, sku: &str, ) -> Result<Decimal>

Get total available quantity for a SKU across a warehouse.

Sums available quantity (on_hand - reserved) across all locations.

Source

pub fn get_total_on_hand(&self, warehouse_id: i32, sku: &str) -> Result<Decimal>

Get total on-hand quantity for a SKU across a warehouse.

Source

pub fn get_movements( &self, filter: MovementFilter, ) -> Result<Vec<LocationMovement>>

Get inventory movements with optional filtering.

§Example
use stateset_embedded::{Commerce, MovementFilter, MovementType};
use chrono::{Utc, Duration};

let commerce = Commerce::new(":memory:")?;

// Get all transfers in the last 7 days
let movements = commerce.warehouse().get_movements(MovementFilter {
    warehouse_id: Some(1),
    movement_type: Some(MovementType::Transfer),
    from_date: Some(Utc::now() - Duration::days(7)),
    limit: Some(100),
    ..Default::default()
})?;
Source

pub fn count_movements(&self, filter: MovementFilter) -> Result<u64>

Count movements matching the filter.

Source

pub fn create_cycle_count(&self, input: CreateCycleCount) -> Result<CycleCount>

Create a cycle count (draft) with its expected lines.

§Example
use stateset_embedded::{Commerce, CreateCycleCount, CreateCycleCountLine};
use rust_decimal_macros::dec;

let commerce = Commerce::new(":memory:")?;

let count = commerce.warehouse().create_cycle_count(CreateCycleCount {
    warehouse_id: 1,
    location_id: Some(1),
    counted_by: Some("counter@example.com".into()),
    lines: vec![CreateCycleCountLine {
        sku: "PROD-001".into(),
        lot_id: None,
        expected_quantity: dec!(100),
    }],
    ..Default::default()
})?;
Source

pub fn get_cycle_count(&self, id: Uuid) -> Result<Option<CycleCount>>

Get a cycle count (with lines) by ID.

Source

pub fn list_cycle_counts( &self, filter: CycleCountFilter, ) -> Result<Vec<CycleCount>>

List cycle counts matching the filter.

Source

pub fn start_cycle_count(&self, id: Uuid) -> Result<CycleCount>

Start a draft cycle count (draftin_progress).

Source

pub fn record_cycle_counts( &self, id: Uuid, counts: Vec<RecordCycleCountLine>, ) -> Result<CycleCount>

Record physical counts against an in-progress cycle count.

Source

pub fn complete_cycle_count(&self, id: Uuid) -> Result<CycleCount>

Complete an in-progress cycle count.

Computes each line’s variance (counted - expected) and applies matching inventory adjustments to location_inventory, recording cycle_count movements for the audit trail.

Source

pub fn cancel_cycle_count(&self, id: Uuid) -> Result<CycleCount>

Cancel a draft or in-progress cycle count. No adjustments are applied.

Trait Implementations§

Source§

impl Debug for WarehouseOps

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