1
//! Stored transaction rows raised for the forms and the logical native.
2

            
3
use std::collections::HashMap;
4

            
5
use finance::price::Price;
6
use finance::split::Split;
7
use finance::tag::Tag;
8
use finance::transaction::Transaction;
9
use server::command::CmdError;
10
use server::logical::{RaisedRow, RowTags, raise_transaction, row_tags};
11
use uuid::Uuid;
12

            
13
pub(crate) struct Detail {
14
    pub(crate) transaction: Transaction,
15
    pub(crate) note: Option<String>,
16
    pub(crate) prices: Vec<Price>,
17
}
18

            
19
/// A raised row with its shared and per-leg split tags.
20
pub(crate) type TaggedRow = (RaisedRow, RowTags);
21

            
22
/// Raise the stored splits to rows with their split tags, or fail with the
23
/// reason the form cannot represent the transaction.
24
10830
pub(crate) fn raise_rows(
25
10830
    splits: &[Split],
26
10830
    split_tags: &HashMap<Uuid, Vec<Tag>>,
27
10830
    prices: &[Price],
28
10830
) -> Result<Vec<TaggedRow>, CmdError> {
29
10830
    raise_transaction(splits, prices)?
30
        .into_iter()
31
15486
        .map(|row| {
32
15486
            let tags = row_tags(&row, split_tags)?;
33
15486
            Ok((row, tags))
34
15486
        })
35
        .collect()
36
10830
}