backbone-inventory 0.17.2

Inventory: stock ledger of record (SLE) + moving-average valuation; emits COGS/asset AccountingPost (Delivery/Receipt -> GL)
Documentation
use serde::{Deserialize, Serialize};
use sqlx::Type;
use std::str::FromStr;
#[cfg(feature = "openapi")]
use utoipa::ToSchema;

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Type)]
#[cfg_attr(feature = "openapi", derive(ToSchema))]
#[serde(rename_all = "snake_case")]
#[sqlx(type_name = "valuation_policy", rename_all = "snake_case")]
pub enum ValuationPolicy {
    Perpetual,
    Periodic,
}

impl std::fmt::Display for ValuationPolicy {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::Perpetual => write!(f, "perpetual"),
            Self::Periodic => write!(f, "periodic"),
        }
    }
}

impl FromStr for ValuationPolicy {
    type Err = String;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s.to_lowercase().as_str() {
            "perpetual" => Ok(Self::Perpetual),
            "periodic" => Ok(Self::Periodic),
            _ => Err(format!("Unknown ValuationPolicy variant: {}", s)),
        }
    }
}

impl Default for ValuationPolicy {
    fn default() -> Self {
        Self::Perpetual
    }
}