bo4e_core/com/
offer_part.rs1use serde::{Deserialize, Serialize};
4
5use crate::traits::{Bo4eMeta, Bo4eObject};
6
7#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
26#[serde(rename_all = "camelCase")]
27pub struct OfferPart {
28 #[serde(flatten)]
30 pub meta: Bo4eMeta,
31
32 #[serde(skip_serializing_if = "Option::is_none")]
34 pub request_sub_reference: Option<String>,
35
36 #[serde(skip_serializing_if = "Option::is_none")]
41 pub position_count: Option<i32>,
42
43 #[serde(skip_serializing_if = "Option::is_none")]
45 pub total_quantity_value: Option<f64>,
46
47 #[serde(skip_serializing_if = "Option::is_none")]
49 pub total_cost_value: Option<f64>,
50
51 #[serde(skip_serializing_if = "Option::is_none")]
53 pub delivery_period_start: Option<String>,
54
55 #[serde(skip_serializing_if = "Option::is_none")]
57 pub delivery_period_end: Option<String>,
58}
59
60impl Bo4eObject for OfferPart {
61 fn type_name_german() -> &'static str {
62 "Angebotsteil"
63 }
64
65 fn type_name_english() -> &'static str {
66 "OfferPart"
67 }
68
69 fn meta(&self) -> &Bo4eMeta {
70 &self.meta
71 }
72
73 fn meta_mut(&mut self) -> &mut Bo4eMeta {
74 &mut self.meta
75 }
76}
77
78#[cfg(test)]
79mod tests {
80 use super::*;
81
82 #[test]
83 fn test_offer_part_default() {
84 let part = OfferPart::default();
85 assert!(part.request_sub_reference.is_none());
86 assert!(part.total_cost_value.is_none());
87 }
88
89 #[test]
90 fn test_offer_part_serialize() {
91 let part = OfferPart {
92 request_sub_reference: Some("LOT-001".to_string()),
93 position_count: Some(5),
94 total_quantity_value: Some(50000.0),
95 total_cost_value: Some(12500.0),
96 ..Default::default()
97 };
98
99 let json = serde_json::to_string(&part).unwrap();
100 assert!(json.contains(r#""requestSubReference":"LOT-001""#));
101 assert!(json.contains(r#""positionCount":5"#));
102 }
103
104 #[test]
105 fn test_offer_part_roundtrip() {
106 let part = OfferPart {
107 meta: Bo4eMeta::with_type("Angebotsteil"),
108 request_sub_reference: Some("LOT-002".to_string()),
109 position_count: Some(3),
110 total_quantity_value: Some(30000.0),
111 total_cost_value: Some(7500.0),
112 delivery_period_start: Some("2024-01-01T00:00:00+01:00".to_string()),
113 delivery_period_end: Some("2024-12-31T23:59:59+01:00".to_string()),
114 };
115
116 let json = serde_json::to_string(&part).unwrap();
117 let parsed: OfferPart = serde_json::from_str(&json).unwrap();
118 assert_eq!(part, parsed);
119 }
120
121 #[test]
122 fn test_bo4e_object_impl() {
123 assert_eq!(OfferPart::type_name_german(), "Angebotsteil");
124 assert_eq!(OfferPart::type_name_english(), "OfferPart");
125 }
126}