Skip to main content

pactole_core/models/
transaction.rs

1use crate::models::balance::Amount;
2use crate::models::names::{AccountName, Metadata};
3use chrono::NaiveDate;
4
5// -------------------------------------------------
6// Events
7// -------------------------------------------------
8
9/// A balanced financial transaction with one or more postings.
10#[derive(Debug, Clone, PartialEq)]
11pub struct Transaction {
12    /// Posting date.
13    pub date: NaiveDate,
14    /// Optional effective date, distinct from the posting date.
15    pub effective_date: Option<NaiveDate>,
16
17    /// Reconciliation status of the transaction.
18    pub status: TransactionStatus,
19    /// Optional declared payee.
20    pub payee: Option<String>,
21    /// Optional human-readable narration.
22    pub narration: Option<String>,
23
24    /// Accounts and amounts making up the transaction.
25    pub postings: Vec<Posting>,
26
27    /// Tags attached to the transaction.
28    pub tags: Vec<String>,
29    /// Links attached to the transaction.
30    pub links: Vec<String>,
31    /// Optional external reference.
32    pub reference: Option<String>,
33    /// Metadata attached to the transaction.
34    pub meta: Metadata,
35}
36
37/// One account-side movement within a transaction.
38#[derive(Debug, Clone, PartialEq)]
39pub struct Posting {
40    /// Account affected by the posting.
41    pub account: AccountName,
42    /// Amount and commodity. `None` may be inferred during validation when
43    /// there is exactly one missing posting amount.
44    pub amount: Option<Amount>,
45    /// Metadata attached to the posting.
46    pub meta: Metadata,
47}
48
49/// Reconciliation status of a transaction.
50#[derive(Debug, Clone, PartialEq)]
51pub enum TransactionStatus {
52    /// The transaction has not been cleared.
53    Uncleared,
54    /// The transaction is pending.
55    Pending,
56    /// The transaction has cleared.
57    Cleared,
58}