pub struct StockAdjustmentRepository;Expand description
The quant staging/apply SQL. Stateless; every method takes the caller’s connection.
Implementations§
Source§impl StockAdjustmentRepository
impl StockAdjustmentRepository
pub fn new() -> Self
Sourcepub async fn lock_quant(
&self,
conn: &mut PgConnection,
selector: QuantSelector,
) -> Result<Option<QuantCountRow>, Error>
pub async fn lock_quant( &self, conn: &mut PgConnection, selector: QuantSelector, ) -> Result<Option<QuantCountRow>, Error>
Lock the addressed quant FOR UPDATE (the reservation-apex row — every
count stage/apply serializes here). None when no quant matches; the
service then either errors (apply) or initializes one (stage).
Sourcepub async fn init_quant(
&self,
conn: &mut PgConnection,
item_id: Uuid,
location_id: Uuid,
) -> Result<Uuid, Error>
pub async fn init_quant( &self, conn: &mut PgConnection, item_id: Uuid, location_id: Uuid, ) -> Result<Uuid, Error>
The quant for (item, location) with no lot, package or owner, created zeroed when there is none yet — the count surface exists even before any stock does. Returns its id; the caller has already verified the location is internal (R13). Created through the quant repository’s creation lock, so two counts that both found no quant still make one.
Sourcepub async fn stage_count(
&self,
conn: &mut PgConnection,
quant_id: Uuid,
counted: Decimal,
diff: Decimal,
) -> Result<(), Error>
pub async fn stage_count( &self, conn: &mut PgConnection, quant_id: Uuid, counted: Decimal, diff: Decimal, ) -> Result<(), Error>
Stage a counted quantity on a quant (T4): record the count and its stored
compute (inventory_diff_quantity = counted - quantity), and raise the
inventory_quantity_set gate that Apply demands. The pending-count partial
index (WHERE inventory_quantity_set = true) is the worklist this feeds.
Sourcepub async fn consume_staged_count(
&self,
conn: &mut PgConnection,
quant_id: Uuid,
) -> Result<(), Error>
pub async fn consume_staged_count( &self, conn: &mut PgConnection, quant_id: Uuid, ) -> Result<(), Error>
Consume the staged count: clear the count fields and drop the
inventory_quantity_set gate. This deliberately does NOT write quantity — the
is_inventory move the apply minted through the engine pipeline is the one writer
that reconciled the quant to the count (its two-step sync maintains quantity,
reserved_quantity, and the T2 stored compute together). Consuming the staging is
what makes re-application a no-op: a second apply finds the gate down and mints
nothing.
Sourcepub async fn staged_counts_at_location(
&self,
conn: &mut PgConnection,
location_id: Uuid,
) -> Result<Vec<StagedCountRow>, Error>
pub async fn staged_counts_at_location( &self, conn: &mut PgConnection, location_id: Uuid, ) -> Result<Vec<StagedCountRow>, Error>
All quants at a location with a staged-but-unapplied count (the pending-count
worklist the partial index WHERE inventory_quantity_set = true serves).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for StockAdjustmentRepository
impl RefUnwindSafe for StockAdjustmentRepository
impl Send for StockAdjustmentRepository
impl Sync for StockAdjustmentRepository
impl Unpin for StockAdjustmentRepository
impl UnsafeUnpin for StockAdjustmentRepository
impl UnwindSafe for StockAdjustmentRepository
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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