Lines
100 %
Functions
Branches
//! Stored transaction rows raised for the forms and the logical native.
use std::collections::HashMap;
use finance::price::Price;
use finance::split::Split;
use finance::tag::Tag;
use finance::transaction::Transaction;
use server::command::CmdError;
use server::logical::{RaisedRow, RowTags, raise_transaction, row_tags};
use uuid::Uuid;
pub(crate) struct Detail {
pub(crate) transaction: Transaction,
pub(crate) note: Option<String>,
pub(crate) prices: Vec<Price>,
}
/// A raised row with its shared and per-leg split tags.
pub(crate) type TaggedRow = (RaisedRow, RowTags);
/// Raise the stored splits to rows with their split tags, or fail with the
/// reason the form cannot represent the transaction.
pub(crate) fn raise_rows(
splits: &[Split],
split_tags: &HashMap<Uuid, Vec<Tag>>,
prices: &[Price],
) -> Result<Vec<TaggedRow>, CmdError> {
raise_transaction(splits, prices)?
.into_iter()
.map(|row| {
let tags = row_tags(&row, split_tags)?;
Ok((row, tags))
})
.collect()