Skip to main content

StockPickingRepository

Struct StockPickingRepository 

Source
pub struct StockPickingRepository;
Expand description

The picking mint/probe/heal SQL. Stateless — every method takes the caller’s connection so the header, its moves, and the projection commit as one unit (moves themselves are minted through the engine’s own guarded transactions).

Implementations§

Source§

impl StockPickingRepository

Source

pub fn new() -> Self

Source

pub async fn insert_transfer( &self, conn: &mut PgConnection, t: &NewPickingRow<'_>, ) -> Result<(), Error>

Insert the transfer header. Leaks the raw sqlx::Error deliberately so the service can turn a unique violation on the name — the composing decorator’s org-scoped arbiter — into a typed duplicate-name error.

Source

pub async fn fetch_transfer( &self, conn: &mut PgConnection, transfer_id: Uuid, ) -> Result<Option<TransferHeaderRow>, Error>

Read one transfer header (probe surface — the projected state is READ here, never asserted by callers).

Source

pub async fn fetch_moves_of_transfer( &self, conn: &mut PgConnection, transfer_id: Uuid, ) -> Result<Vec<MoveStateRow>, Error>

Read a transfer’s member moves (the projection inputs, for the probe surface).

Source

pub async fn move_ids_of_transfer( &self, conn: &mut PgConnection, transfer_id: Uuid, ) -> Result<Vec<Uuid>, Error>

The ids of a transfer’s member moves (the validate surface iterates these).

Source

pub async fn fetch_operation_type( &self, conn: &mut PgConnection, operation_type_id: Uuid, ) -> Result<Option<OperationTypeFacts>, Error>

The operation type’s facts. None when the type does not exist or is archived.

Source

pub async fn find_open_group_picking( &self, conn: &mut PgConnection, picking_type_id: Uuid, location_id: Uuid, location_dest_id: Uuid, partner_id: Option<Uuid>, origin: Option<&str>, ) -> Result<Option<Uuid>, Error>

The OPEN transfer a move would join when it is grouped for fulfillment: the most recently scheduled transfer whose operation type, source, destination, partner, and origin (the procurement-group stand-in — moves launched for one source document share it) all match, and whose projection has not reached a terminal state (done picks nothing more up; a cancel never reopens). None when no open transfer matches — the caller mints one.

Source

pub async fn resolve_internal_location( &self, conn: &mut PgConnection, warehouse_id: Uuid, ) -> Result<Option<Uuid>, Error>

The warehouse’s stock location: the internal location the warehouse tree resolves to (deterministic: shallowest in the tree, then name). None when the warehouse has no internal location yet — the caller decides whether to bootstrap one.

Source

pub async fn resolve_inventory_loss_location( &self, conn: &mut PgConnection, ) -> Result<Option<Uuid>, Error>

The inventory-loss location (the far end of every adjustment move). None when none exists — the caller decides whether to bootstrap one.

Source

pub async fn ensure_internal_location( &self, conn: &mut PgConnection, warehouse_id: Uuid, ) -> Result<Uuid, Error>

Bootstrap a warehouse’s stock location (internal usage). The adjustment door and the picking mint use this the first time a warehouse without a location tree stages a count or mints a picking — a physical grain needs a location, and minting the warehouse’s own stock location is the least-surprise resolution.

Source

pub async fn ensure_inventory_loss_location( &self, conn: &mut PgConnection, ) -> Result<Uuid, Error>

Bootstrap the inventory-loss location (usage inventory — the scrap / adjustment sink). Shared root trees would normally seed this; the module ships no location seed yet, so the door mints it on first use.

Source

pub async fn resolve_partner_location( &self, conn: &mut PgConnection, usage: &str, ) -> Result<Option<Uuid>, Error>

Resolve the location of a partner usage (supplier / customer). None when none exists — the caller decides whether to bootstrap one.

Source

pub async fn ensure_partner_location( &self, conn: &mut PgConnection, usage: &str, ) -> Result<Uuid, Error>

Bootstrap the counterpart location for a partner usage (supplier — the far end of every goods receipt; customer — the far end of every delivery). Voucher doors are warehouse-grain, moves are location-grain: this is the resolve-or-mint that gives the door’s moves their virtual counterpart endpoint.

Source

pub async fn ensure_quant_surface( &self, conn: &mut PgConnection, item_id: Uuid, location_id: Uuid, warehouse_id: Option<Uuid>, ) -> Result<(), Error>

The quant-surface backfill: guarantee a quant row exists at the bin grain (item, location, all tracking dims NULL), initialized from the Bin balance of the location’s warehouse. Stock seeded through the legacy voucher paths wrote Bins without quants; converged moves draw from quants, so the first converged touch of a grain heals it. Idempotent by construction (NOT EXISTS guard + the same advisory-lock pattern QuantRepository::lock_or_init uses — the unique index does not dedup NULL dimensions, so creation must serialize). A second call finds the row and does nothing: this is a one-time catch-up, never an ongoing second writer of quantity (the move pipeline is the only ongoing writer).

Source

pub async fn find_adjustment_moves( &self, conn: &mut PgConnection, item_id: Uuid, location_a: Uuid, location_b: Uuid, ) -> Result<Vec<AdjustmentMoveRow>, Error>

The adjustment door’s mint-once gate: an existing is_inventory move addressing this item between exactly these two locations (either direction — the count direction only flips the pair). Live moves first (resume candidates), then done ones (the already-applied evidence), newest first.

Trait Implementations§

Source§

impl Default for StockPickingRepository

Source§

fn default() -> Self

Returns the “default value” for a type. 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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