okane_core/report/transaction.rs
1use chrono::NaiveDate;
2
3use super::{
4 account::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 /// Payee of the posting. By default this is the enclosing transaction's
29 /// payee; per-posting payee overrides via metadata are not implemented yet.
30 pub payee: &'ctx str,
31
32 /// Amount of the posting described in the Ledger.
33 // Note this is not PostingAmount,
34 // as deduced posting may have non-single commodity amount.
35 pub amount: Amount<'ctx>,
36
37 /// Amount of the posting in cost basis.
38 /// Some time this is useful for a few use cases:
39 /// - To balance within the transaction, we prefer this amount.
40 pub converted_amount: Option<SingleAmount<'ctx>>,
41}