Skip to main content

Lots

Struct Lots 

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

Lot/Batch tracking management interface.

Implementations§

Source§

impl Lots

Source

pub fn create(&self, input: CreateLot) -> Result<Lot>

Create a new lot.

§Example
use stateset_embedded::{Commerce, CreateLot};
use chrono::{Utc, Duration};
use rust_decimal_macros::dec;

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

let lot = commerce.lots().create(CreateLot {
    lot_number: Some("BATCH-001".into()),
    sku: "PROD-001".into(),
    quantity_produced: dec!(500),
    production_date: Some(Utc::now()),
    expiration_date: Some(Utc::now() + Duration::days(180)),
    ..Default::default()
})?;
Source

pub fn get(&self, id: Uuid) -> Result<Option<Lot>>

Get a lot by ID.

Source

pub fn get_by_number(&self, lot_number: &str) -> Result<Option<Lot>>

Get a lot by lot number.

Source

pub fn list(&self, filter: LotFilter) -> Result<Vec<Lot>>

List lots with optional filtering.

§Example
use stateset_embedded::{Commerce, LotFilter, LotStatus};

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

// Get all active lots for a SKU
let lots = commerce.lots().list(LotFilter {
    sku: Some("PROD-001".into()),
    status: Some(LotStatus::Active),
    ..Default::default()
})?;
Source

pub fn update(&self, id: Uuid, input: UpdateLot) -> Result<Lot>

Update a lot.

Source

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

Delete a lot (only if unused).

Source

pub fn quarantine(&self, id: Uuid, reason: &str) -> Result<Lot>

Quarantine a lot (prevent usage).

§Example
use stateset_embedded::Commerce;
use uuid::Uuid;

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

commerce.lots().quarantine(Uuid::new_v4(), "Quality issue detected")?;
Source

pub fn release_quarantine(&self, id: Uuid) -> Result<Lot>

Release a lot from quarantine.

Source

pub fn adjust(&self, input: AdjustLot) -> Result<LotTransaction>

Adjust lot quantity (positive or negative).

§Example
use stateset_embedded::{Commerce, AdjustLot};
use rust_decimal_macros::dec;
use uuid::Uuid;

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

// Remove 10 units due to damage
commerce.lots().adjust(AdjustLot {
    lot_id: Uuid::new_v4(),
    quantity: dec!(-10),
    reason: "Damaged in storage".into(),
    performed_by: Some("warehouse_user".into()),
    ..Default::default()
})?;
Source

pub fn consume(&self, input: ConsumeLot) -> Result<LotTransaction>

Consume quantity from a lot.

§Example
use stateset_embedded::{Commerce, ConsumeLot};
use rust_decimal_macros::dec;
use uuid::Uuid;

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

commerce.lots().consume(ConsumeLot {
    lot_id: Uuid::new_v4(),
    quantity: dec!(25),
    reference_type: "work_order".into(),
    reference_id: Uuid::new_v4(),
    ..Default::default()
})?;
Source

pub fn reserve(&self, input: ReserveLot) -> Result<Uuid>

Reserve quantity in a lot.

Returns the reservation ID which can be used to release or confirm the reservation.

Source

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

Release a reservation (cancel it without consuming).

Source

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

Confirm a reservation (convert to actual consumption).

Source

pub fn transfer(&self, input: TransferLot) -> Result<LotTransaction>

Transfer lot to a different location.

Source

pub fn split(&self, input: SplitLot) -> Result<Lot>

Split a lot into two.

§Example
use stateset_embedded::{Commerce, SplitLot};
use rust_decimal_macros::dec;
use uuid::Uuid;

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

// Split 100 units into a new lot
let new_lot = commerce.lots().split(SplitLot {
    source_lot_id: Uuid::new_v4(),
    new_lot_number: Some("LOT-2025-001B".into()),
    quantity: dec!(100),
    reason: Some("Customer allocation".into()),
    ..Default::default()
})?;
Source

pub fn merge(&self, input: MergeLots) -> Result<Lot>

Merge multiple lots into one.

Source

pub fn add_certificate( &self, input: AddLotCertificate, ) -> Result<LotCertificate>

Add a certificate to a lot.

§Example
use stateset_embedded::{Commerce, AddLotCertificate, CertificateType};
use uuid::Uuid;

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

commerce.lots().add_certificate(AddLotCertificate {
    lot_id: Uuid::new_v4(),
    certificate_type: CertificateType::Coa,
    document_url: Some("https://storage.example.com/certs/coa-123.pdf".into()),
    issued_by: Some("Quality Lab Inc.".into()),
    ..Default::default()
})?;
Source

pub fn get_certificates(&self, lot_id: Uuid) -> Result<Vec<LotCertificate>>

Get certificates for a lot.

Source

pub fn delete_certificate(&self, certificate_id: Uuid) -> Result<()>

Remove a certificate from a lot.

Source

pub fn get_locations(&self, lot_id: Uuid) -> Result<Vec<LotLocation>>

Get lot quantities by location.

Source

pub fn get_quantity_at_location( &self, lot_id: Uuid, location_id: i32, ) -> Result<Option<Decimal>>

Get quantity at a specific location.

Source

pub fn get_transactions( &self, lot_id: Uuid, limit: u32, ) -> Result<Vec<LotTransaction>>

Get transaction history for a lot.

§Example
use stateset_embedded::Commerce;
use uuid::Uuid;

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

let transactions = commerce.lots().get_transactions(
    Uuid::new_v4(),
    100,  // limit
)?;

for tx in transactions {
    println!("{:?}: {} units", tx.transaction_type, tx.quantity);
}
Source

pub fn trace(&self, lot_id: Uuid) -> Result<TraceabilityResult>

Get full bidirectional traceability (upstream and downstream).

§Example
use stateset_embedded::Commerce;
use uuid::Uuid;

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

let trace = commerce.lots().trace(Uuid::new_v4())?;

println!("Upstream sources: {} nodes", trace.upstream.len());
println!("Downstream destinations: {} nodes", trace.downstream.len());
Source

pub fn get_expiring_lots(&self, days: i32) -> Result<Vec<Lot>>

Get lots expiring within a number of days.

Source

pub fn get_expired_lots(&self) -> Result<Vec<Lot>>

Get already expired lots.

Source

pub fn get_available_lots_for_sku(&self, sku: &str) -> Result<Vec<Lot>>

Get lots with available quantity for a SKU.

Returns lots ordered by production date (FIFO).

Source

pub fn count(&self, filter: LotFilter) -> Result<u64>

Count lots matching filter.

Source

pub fn create_batch(&self, inputs: Vec<CreateLot>) -> Result<BatchResult<Lot>>

Create multiple lots at once.

Source

pub fn get_batch(&self, ids: Vec<Uuid>) -> Result<Vec<Lot>>

Get multiple lots by ID.

Source

pub fn get_active_lots(&self, sku: &str) -> Result<Vec<Lot>>

Get all active lots for a SKU.

Source

pub fn get_quarantined(&self) -> Result<Vec<Lot>>

Get all quarantined lots.

Trait Implementations§

Source§

impl Debug for Lots

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Lots

§

impl !UnwindSafe for Lots

§

impl Freeze for Lots

§

impl Send for Lots

§

impl Sync for Lots

§

impl Unpin for Lots

§

impl UnsafeUnpin for Lots

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