pub struct WarehouseOps { /* private fields */ }Expand description
Warehouse and Location management interface.
Implementations§
Source§impl WarehouseOps
impl WarehouseOps
Sourcepub fn create_warehouse(&self, input: CreateWarehouse) -> Result<Warehouse>
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()),
})?;Sourcepub fn get_warehouse_by_code(&self, code: &str) -> Result<Option<Warehouse>>
pub fn get_warehouse_by_code(&self, code: &str) -> Result<Option<Warehouse>>
Get a warehouse by code.
Sourcepub fn update_warehouse(
&self,
id: i32,
input: UpdateWarehouse,
) -> Result<Warehouse>
pub fn update_warehouse( &self, id: i32, input: UpdateWarehouse, ) -> Result<Warehouse>
Update a warehouse.
Sourcepub fn list_warehouses(&self, filter: WarehouseFilter) -> Result<Vec<Warehouse>>
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()
})?;Sourcepub fn delete_warehouse(&self, id: i32) -> Result<()>
pub fn delete_warehouse(&self, id: i32) -> Result<()>
Delete a warehouse. Only warehouses without locations can be deleted.
Sourcepub fn count_warehouses(&self, filter: WarehouseFilter) -> Result<u64>
pub fn count_warehouses(&self, filter: WarehouseFilter) -> Result<u64>
Count warehouses matching the filter.
Sourcepub fn create_zone(&self, input: CreateZone) -> Result<Zone>
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”).
Sourcepub fn update_zone(&self, id: i32, input: UpdateZone) -> Result<Zone>
pub fn update_zone(&self, id: i32, input: UpdateZone) -> Result<Zone>
Update a zone.
Sourcepub fn delete_zone(&self, id: i32) -> Result<()>
pub fn delete_zone(&self, id: i32) -> Result<()>
Delete a zone.
Sourcepub fn create_location(&self, input: CreateLocation) -> Result<Location>
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"Sourcepub fn get_location_by_code(
&self,
warehouse_id: i32,
code: &str,
) -> Result<Option<Location>>
pub fn get_location_by_code( &self, warehouse_id: i32, code: &str, ) -> Result<Option<Location>>
Get a location by code within a warehouse.
Sourcepub fn update_location(
&self,
id: i32,
input: UpdateLocation,
) -> Result<Location>
pub fn update_location( &self, id: i32, input: UpdateLocation, ) -> Result<Location>
Update a location.
Sourcepub fn list_locations(&self, filter: LocationFilter) -> Result<Vec<Location>>
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()
})?;Sourcepub fn delete_location(&self, id: i32) -> Result<()>
pub fn delete_location(&self, id: i32) -> Result<()>
Delete a location. Only locations without inventory can be deleted.
Sourcepub fn count_locations(&self, filter: LocationFilter) -> Result<u64>
pub fn count_locations(&self, filter: LocationFilter) -> Result<u64>
Count locations matching the filter.
Sourcepub fn get_locations_for_warehouse(
&self,
warehouse_id: i32,
) -> Result<Vec<Location>>
pub fn get_locations_for_warehouse( &self, warehouse_id: i32, ) -> Result<Vec<Location>>
Get all active locations for a warehouse.
Sourcepub fn get_pickable_locations(
&self,
warehouse_id: i32,
sku: &str,
) -> Result<Vec<Location>>
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.
Sourcepub fn get_receivable_locations(
&self,
warehouse_id: i32,
) -> Result<Vec<Location>>
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).
Sourcepub fn create_locations_batch(
&self,
inputs: Vec<CreateLocation>,
) -> Result<BatchResult<Location>>
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.
Sourcepub fn get_locations_batch(&self, ids: Vec<i32>) -> Result<Vec<Location>>
pub fn get_locations_batch(&self, ids: Vec<i32>) -> Result<Vec<Location>>
Get multiple locations by ID.
Sourcepub fn get_location_inventory(
&self,
location_id: i32,
) -> Result<Vec<LocationInventory>>
pub fn get_location_inventory( &self, location_id: i32, ) -> Result<Vec<LocationInventory>>
Get all inventory at a specific location.
Sourcepub fn get_inventory_for_sku(
&self,
warehouse_id: i32,
sku: &str,
) -> Result<Vec<LocationInventory>>
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.
Sourcepub fn adjust_inventory(
&self,
input: AdjustLocationInventory,
) -> Result<LocationInventory>
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);Sourcepub fn move_inventory(&self, input: MoveInventory) -> Result<LocationMovement>
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()),
})?;Sourcepub fn list_location_inventory(
&self,
filter: LocationInventoryFilter,
) -> Result<Vec<LocationInventory>>
pub fn list_location_inventory( &self, filter: LocationInventoryFilter, ) -> Result<Vec<LocationInventory>>
List location inventory with optional filtering.
Sourcepub fn get_total_available(
&self,
warehouse_id: i32,
sku: &str,
) -> Result<Decimal>
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.
Sourcepub fn get_total_on_hand(&self, warehouse_id: i32, sku: &str) -> Result<Decimal>
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.
Sourcepub fn get_movements(
&self,
filter: MovementFilter,
) -> Result<Vec<LocationMovement>>
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()
})?;Sourcepub fn count_movements(&self, filter: MovementFilter) -> Result<u64>
pub fn count_movements(&self, filter: MovementFilter) -> Result<u64>
Count movements matching the filter.
Sourcepub fn create_cycle_count(&self, input: CreateCycleCount) -> Result<CycleCount>
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()
})?;Sourcepub fn get_cycle_count(&self, id: Uuid) -> Result<Option<CycleCount>>
pub fn get_cycle_count(&self, id: Uuid) -> Result<Option<CycleCount>>
Get a cycle count (with lines) by ID.
Sourcepub fn list_cycle_counts(
&self,
filter: CycleCountFilter,
) -> Result<Vec<CycleCount>>
pub fn list_cycle_counts( &self, filter: CycleCountFilter, ) -> Result<Vec<CycleCount>>
List cycle counts matching the filter.
Sourcepub fn start_cycle_count(&self, id: Uuid) -> Result<CycleCount>
pub fn start_cycle_count(&self, id: Uuid) -> Result<CycleCount>
Start a draft cycle count (draft → in_progress).
Sourcepub fn record_cycle_counts(
&self,
id: Uuid,
counts: Vec<RecordCycleCountLine>,
) -> Result<CycleCount>
pub fn record_cycle_counts( &self, id: Uuid, counts: Vec<RecordCycleCountLine>, ) -> Result<CycleCount>
Record physical counts against an in-progress cycle count.
Sourcepub fn complete_cycle_count(&self, id: Uuid) -> Result<CycleCount>
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.
Sourcepub fn cancel_cycle_count(&self, id: Uuid) -> Result<CycleCount>
pub fn cancel_cycle_count(&self, id: Uuid) -> Result<CycleCount>
Cancel a draft or in-progress cycle count. No adjustments are applied.