tktax_amazon/
amazon_tx.rs

1// ---------------- [ File: tktax-amazon/src/amazon_tx.rs ]
2crate::ix!();
3
4#[derive(Getters,Builder,Clone,Debug,Serialize,Deserialize)]
5#[getset(get="pub")]
6#[builder(setter(into))]
7pub struct AmazonTx {
8    quantity:     i32,
9    unit_price:   MonetaryAmount,
10    order_date:   NaiveDate,
11    product_name: String,
12}
13
14impl From<&AmazonTx1> for AmazonTx {
15
16    fn from(x: &AmazonTx1) -> Self {
17
18        let order_date = NaiveDate::parse_from_str(&x.order_date(), "%m/%d/%Y").unwrap();
19
20        Self {
21            quantity:     x.quantity().parse::<i32>().unwrap(),
22            unit_price:   parse_price(&x.purchase_price_per_unit()).unwrap(),
23            order_date,
24            product_name: x.title().clone(),
25        }
26    }
27}
28
29impl From<&AmazonTx2> for AmazonTx {
30
31    fn from(x: &AmazonTx2) -> Self {
32
33        let order_date 
34            = NaiveDateTime::parse_from_str(&x.order_date(), "%m/%d/%Y %H:%M:%S").unwrap().date();
35
36        Self {
37            quantity:     x.quantity().parse::<i32>().unwrap(),
38            unit_price:   parse_price(&x.unit_price()).unwrap(),
39            order_date,
40            product_name: x.product_name().clone(),
41        }
42    }
43}