Skip to main content

commerce_types/
order.rs

1use crate::core::*;
2use chrono::{DateTime, NaiveDate, Utc};
3use currency_4217::Money;
4use schemars::JsonSchema;
5use serde::{Deserialize, Serialize};
6use std::collections::HashMap;
7
8/// The full request datatype for a purchase order
9#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
10pub struct OrderRequest {
11    /// Header of the order request
12    ///
13    /// This contains metadata about the order such as the `order_id`,
14    /// the address where the order must be shipped to and additional information.
15    pub header: OrderRequestHeader,
16    /// Items of the order
17    ///
18    /// These are the concrete items that were purchased in this order
19    pub items: Vec<ItemOut>,
20}
21
22/// Header of an order-request
23#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
24pub struct OrderRequestHeader {
25    /// Identifier of this order
26    pub order_id: String,
27    /// Date of the order
28    pub order_date: DateTime<Utc>,
29    /// Specifies weather or not this was a new order, or a modification to an existing one
30    pub order_type: OrderType,
31    /// Sum of all item prices plus shipping cost
32    pub total: Money,
33    /// Shipping Address
34    pub ship_to: Address,
35    /// Billing Address ( may be identical to shipping address )
36    pub bill_to: Address,
37    /// Shipping cost
38    pub shipping: Option<Money>,
39    /// Tax
40    pub tax: Option<Money>,
41    /// Optional comments on this order
42    pub comments: Option<String>,
43}
44
45/// A single item position in the purchase order
46#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
47pub struct ItemOut {
48    /// The line-number in the list of items that are purchased.
49    pub line_number: u32,
50    /// Total quantity of that item
51    pub quantity: u32,
52    /// Optional requested date of delivery, if possible
53    pub requested_delivery_date: Option<NaiveDate>,
54    /// Item that was purchased
55    pub item: Item,
56}
57
58/// Datatype for a single item - bundles item-id and item-detail
59#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
60pub struct Item {
61    /// ID of the requested item
62    pub item_id: ItemID,
63    /// Additional information like unit-price, description, unit of measure etc.
64    pub detail: ItemDetail,
65}
66
67/// Supplier and buyer part/item ID
68#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
69pub struct ItemID {
70    /// If known, the buyer can supply his/her own ID for this item
71    ///
72    /// If specified, this information can be used to map the item into the buyers IT-Systems
73    pub buyer_part_id: Option<String>,
74    /// Item-ID from the supplier
75    pub supplier_part_id: String,
76}
77
78/// Details of a single position in the purchase order
79#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
80pub struct ItemDetail {
81    /// For goods: price per unit
82    pub unit_price: Option<Money>,
83
84    /// Human-readable description
85    pub description: String,
86
87    /// Unit of measure as ISO String (e.g. "KG" for kilogram) - used for goods.
88    /// For services prefer `unit_rate` (cXML deprecates UnitPrice+UOM for services).
89    pub unit_of_measure: Option<String>,
90
91    pub classification: Option<Classification>,
92    pub manufacturer: Option<ManufacturerInfo>,
93    pub extrinsic: Option<HashMap<String, String>>,
94
95    /// Services: cXML-style service pricing (preferred over `unit_price` for services)
96    pub unit_rate: Option<UnitRate>,
97
98    /// Services: detailed info (labor/fee/travel), like in cXML `<SpendDetail>`
99    pub spend_detail: Option<SpendDetail>,
100}
101
102/// Information about the manufacturer
103#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
104pub struct ManufacturerInfo {
105    pub part_id: String,
106    pub name: String,
107}
108
109/// Classification (UNSPSC, ECLASS, …)
110#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
111pub struct Classification {
112    pub domain: ClassificationDomain,
113    pub code: String,
114}
115
116#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
117pub enum ClassificationDomain {
118    UNSPSC,
119    ECLASS,
120    Custom(String),
121}
122
123/// Defines if the order was "new", an "update" or should be "delete"d
124#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
125pub enum OrderType {
126    New,
127    Update,
128    Delete,
129}