[][src]Struct doublecount::Transaction

pub struct Transaction {
    pub description: Option<String>,
    pub date: NaiveDate,
    pub elements: Vec<TransactionElement>,
}

A movement of Commodity between two or more accounts on a given date. Implements Action so it can be applied to change AccountStates.

The sum of the Commodity amounts contained within a transaction's TransactionElements needs to be equal to zero, or one of the elements needs to have a None value amount.

Fields

description: Option<String>

Description of this transaction.

date: NaiveDate

The date that the transaction occurred.

elements: Vec<TransactionElement>

Elements which compose this transaction.

See Transaction for more information about the constraints which apply to this field.

Methods

impl Transaction[src]

pub fn new(
    description: Option<String>,
    date: NaiveDate,
    elements: Vec<TransactionElement>
) -> Transaction
[src]

Create a new Transaction.

pub fn new_simple(
    description: Option<&str>,
    date: NaiveDate,
    from_account: AccountID,
    to_account: AccountID,
    amount: Commodity,
    exchange_rate: Option<ExchangeRate>
) -> Transaction
[src]

Create a new simple Transaction, containing only two elements, transfering an amount from from_account to to_account on the given date, with the given exchange_rate (required if the currencies of the accounts are different).

Example

use doublecount::Account;
use commodity::{CommodityType, Commodity};
use chrono::Local;
use std::str::FromStr;

let aud = Rc::from(CommodityType::from_currency_alpha3("AUD").unwrap());

let account1 = Rc::from(Account::new(Some("Account 1"), aud.id, None));
let account2 = Rc::from(Account::new(Some("Account 2"), aud.id, None));

let transaction = Transaction::new_simple(
   Some("balancing"),
   Local::today().naive_local(),
   account1.id,
   account2.id,
   Commodity::from_str("100.0 AUD").unwrap(),
   None,
);

assert_eq!(2, transaction.elements.len());
let element0 = transaction.elements.get(0).unwrap();
let element1 = transaction.elements.get(1).unwrap();
assert_eq!(Some(Commodity::from_str("-100.0 AUD").unwrap()), element0.amount);
assert_eq!(account1.id, element0.account_id);
assert_eq!(account2.id, element1.account_id);
assert_eq!(None, element1.amount);

pub fn get_element(&self, account_id: &AccountID) -> Option<&TransactionElement>[src]

Get the TransactionElement associated with the given Account's id.

Trait Implementations

impl Action for Transaction[src]

impl Clone for Transaction[src]

impl Debug for Transaction[src]

impl<'de> Deserialize<'de> for Transaction[src]

impl Display for Transaction[src]

impl Serialize for Transaction[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: Deserialize<'de>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.