Skip to main content

ValuationOverlayRepository

Struct ValuationOverlayRepository 

Source
pub struct ValuationOverlayRepository;
Expand description

Hand-owned SQL for the valuation overlay. Stateless (methods take the caller’s connection or run scoped on the pool), mirroring super::GlVoucherRepository.

Implementations§

Source§

impl ValuationOverlayRepository

Source

pub fn new() -> Self

Source

pub async fn fetch_posture( &self, pool: &PgPool, ) -> Result<Option<PostureRow>, Error>

Read the caller’s org-unit valuation settings row. None when the org unit has no row — the caller applies the runtime defaults (average / perpetual / anglo off), which makes rolling the module out a no-op for tenants that never configure it.

Source

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

The same posture read on the CALLER’S connection — the variant the move engine uses inside its open movement transaction (the ambient org scope is already bound there, so the fenced read is correct without opening a second transaction).

Source

pub async fn fetch_location_valuation_override( &self, pool: &PgPool, location_id: Uuid, ) -> Result<Option<Uuid>, Error>

A location’s valuation-account override, when set. None = no override (the caller falls through to the door-header account).

The read runs org-scoped: locations are shared masters under the composition’s root-shared fence, so a scoped read resolves the override for tenant-specific and shared locations alike.

Source

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

The per-unit shipping weight of one stock item (0 = unweighted; the weight basis of a landed-cost split — an all-zero weight basis is the loud zero-denominator case).

Source

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

Read one landed-cost header.

Source

pub async fn fetch_lc_lines( &self, conn: &mut PgConnection, lc_id: Uuid, ) -> Result<Vec<LcLineRow>, Error>

Read the landed cost’s charge lines.

Source

pub async fn insert_landed_cost_draft( &self, conn: &mut PgConnection, lc: &NewLandedCostRow<'_>, ) -> Result<(), Error>

Insert a draft landed-cost header. posting_state starts not_applicable: a draft has no GL leg; validation arms pending in the same transaction that mints the revaluation SLE rows (the move-engine arming pattern).

Source

pub async fn insert_lc_line( &self, conn: &mut PgConnection, l: &NewLcLineRow<'_>, ) -> Result<(), Error>

Insert one cost line of a draft landed cost.

Source

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

The target receipt of a landed cost, as its validation reads it: the receipt number the door stamped as origin on every line move, the header inventory account (the fallback of the debit leg’s account-resolution chain), and the status (a landed cost only ever targets a receipt whose moves are DONE; the service derives that from the moves themselves). Takes the caller’s connection.

Source

pub async fn mark_lc_validated( &self, conn: &mut PgConnection, lc_id: Uuid, amount_total: Decimal, ) -> Result<(), Error>

Flip a draft landed cost to done and arm its GL leg pending — one transaction together with the revaluation SLE rows the engine verb minted before this call inside the caller’s unit of work. amount_total is the document’s Σ cost amounts.

Source

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

Cancel a DRAFT landed cost (a done one can never cancel — the reversal pattern is a negative-amount landed cost). A draft posted no GL, so its posting state retires to not_applicable.

Source

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

Delete the landed cost’s worksheet rows. The worksheet is a RECOMPUTE SURFACE, not a ledger: every (re)validation deletes and recreates it wholesale. The only accounting identity is the posted journal entry.

Source

pub async fn insert_worksheet_row( &self, conn: &mut PgConnection, w: &NewWorksheetRow, ) -> Result<(), Error>

Insert one worksheet row (the caller writes them ordered by move_line_id so the last-line-eats-the-rounding-diff recipient is deterministic).

Source

pub async fn fetch_worksheet( &self, conn: &mut PgConnection, lc_id: Uuid, ) -> Result<Vec<WorksheetRow>, Error>

Read the landed cost’s worksheet back (tests + GL repost reconstruction).

Trait Implementations§

Source§

impl Default for ValuationOverlayRepository

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