Skip to main content

pactole_core/models/
declarations.rs

1use crate::models::names::{AccountName, CommodityName, Metadata};
2use chrono::NaiveDate;
3
4// -------------------------------------------------
5// Declarations
6// -------------------------------------------------
7
8/// Opens an account on a given date.
9#[derive(Debug, Clone, PartialEq)]
10pub struct Open {
11    /// Date on which the account becomes available.
12    pub date: NaiveDate,
13    /// Account being opened.
14    pub account: AccountName,
15    /// Beancount-style optional list of commodities the account is
16    /// restricted to, e.g. `EUR` or `EUR,USD`. Empty when the `open`
17    /// directive doesn't list any commodity, meaning the account is
18    /// unrestricted. When non-empty, [`crate::validation::validate_journal`]
19    /// rejects any posting on this account (including auto-balanced ones)
20    /// using a commodity outside this list.
21    pub commodities: Vec<CommodityName>,
22    /// Optional description of the account.
23    pub description: Option<String>,
24    /// Metadata attached to the directive.
25    pub meta: Metadata,
26}
27
28/// Closes an account on a given date.
29#[derive(Debug, Clone, PartialEq)]
30pub struct Close {
31    /// Date on which the account becomes unavailable.
32    pub date: NaiveDate,
33    /// Account being closed.
34    pub account: AccountName,
35    /// Metadata attached to the directive.
36    pub meta: Metadata,
37}
38
39/// Declares a commodity on a given date.
40#[derive(Debug, Clone, PartialEq)]
41pub struct Commodity {
42    /// Date of the declaration.
43    pub date: NaiveDate,
44    /// Declared commodity name.
45    pub name: CommodityName,
46    /// Metadata attached to the directive.
47    pub meta: Metadata,
48}
49
50/// Declares a payee as "known" (see `ValidationError::PayeeNotDeclared`).
51///
52/// Unlike `Open`/`Commodity`, this carries no date: a payee has no
53/// temporal life cycle, so only its presence in the journal matters, not
54/// where it appears relative to the transactions using it.
55#[derive(Debug, Clone, PartialEq)]
56pub struct Payee {
57    /// Name used by transactions referring to this payee.
58    pub name: String,
59    /// Metadata attached to the directive.
60    pub meta: Metadata,
61}