okane_core/report/
transaction.rs

1use chrono::NaiveDate;
2
3use super::{
4    context::Account,
5    eval::{Amount, SingleAmount},
6};
7
8/// Evaluated transaction, already processed to have right balance.
9// TODO: Rename it to EvaluatedTxn?
10#[derive(Debug, PartialEq, Eq)]
11#[non_exhaustive]
12pub struct Transaction<'ctx> {
13    pub date: NaiveDate,
14    // Posting in the transaction.
15    // Note this MUST be a Box instead of &[Posting],
16    // as Posting is a [Drop] and we can't skip calling Drop,
17    // otherwise we leave allocated memory for Amount HashMap.
18    pub postings: bumpalo::boxed::Box<'ctx, [Posting<'ctx>]>,
19}
20
21/// Evaluated posting of the transaction.
22#[derive(Debug, Clone, PartialEq, Eq)]
23#[non_exhaustive]
24pub struct Posting<'ctx> {
25    /// Account of the posting.
26    pub account: Account<'ctx>,
27
28    /// Amount of the posting described in the Ledger.
29    // Note this is not PostingAmount,
30    // as deduced posting may have non-single commodity amount.
31    pub amount: Amount<'ctx>,
32
33    /// Amount of the posting in cost basis.
34    /// Some time this is useful for a few use cases:
35    /// - To balance within the transaction, we prefer this amount.
36    pub converted_amount: Option<SingleAmount<'ctx>>,
37}