backbone_inventory/domain/entity/
inventory_cost_method.rs1use serde::{Deserialize, Serialize};
2use sqlx::Type;
3use std::str::FromStr;
4#[cfg(feature = "openapi")]
5use utoipa::ToSchema;
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Type)]
8#[cfg_attr(feature = "openapi", derive(ToSchema))]
9#[serde(rename_all = "snake_case")]
10#[sqlx(type_name = "inventory_cost_method", rename_all = "snake_case")]
11pub enum InventoryCostMethod {
12 Average,
13 Fifo,
14 Standard,
15}
16
17impl std::fmt::Display for InventoryCostMethod {
18 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
19 match self {
20 Self::Average => write!(f, "average"),
21 Self::Fifo => write!(f, "fifo"),
22 Self::Standard => write!(f, "standard"),
23 }
24 }
25}
26
27impl FromStr for InventoryCostMethod {
28 type Err = String;
29
30 fn from_str(s: &str) -> Result<Self, Self::Err> {
31 match s.to_lowercase().as_str() {
32 "average" => Ok(Self::Average),
33 "fifo" => Ok(Self::Fifo),
34 "standard" => Ok(Self::Standard),
35 _ => Err(format!("Unknown InventoryCostMethod variant: {}", s)),
36 }
37 }
38}
39
40impl Default for InventoryCostMethod {
41 fn default() -> Self {
42 Self::Average
43 }
44}