tktax-amazon 0.2.2

High-performance crate for parsing, fusing, and exporting Amazon transaction data for financial recordkeeping.
Documentation
// ---------------- [ File: tktax-amazon/src/amazon_item_map.rs ]
crate::ix!();

#[derive(Getters,Debug,Serialize,Deserialize)]
#[getset(get="pub")]
pub struct IndexedAmazonTx {
    quantity:     i32,
    index:        String,
    unit_price:   MonetaryAmount,
    order_date:   NaiveDate,
    product_name: String,
}

impl AmazonTxn for IndexedAmazonTx {}

pub type AmazonItemMap = HashMap<String,AmazonTx>;

/// might return None if we have no way to create it due to missing items in ProgramConfig
///
pub fn create_amazon_item_map(config: &AmazonConfig) -> Option<AmazonItemMap> {

    let contents = std::fs::read(&config.txfile()).unwrap();
    let txns     = parse_amazon_csv::<IndexedAmazonTx>(&contents).unwrap();

    let mut x = HashMap::new();

    for tx in txns.iter() {

        let amazon_tx = AmazonTxBuilder::default()
            .quantity(*tx.quantity())
            .unit_price(*tx.unit_price())
            .order_date(tx.order_date().clone())
            .product_name(tx.product_name().clone())
            .build()
            .unwrap();

        x.insert(tx.index.clone(), amazon_tx);
    }

    Some(x)
}