[−][src]Struct doublecount::Transaction
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 amount
s 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]
description: Option<String>,
date: NaiveDate,
elements: Vec<TransactionElement>
) -> Transaction
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]
description: Option<&str>,
date: NaiveDate,
from_account: AccountID,
to_account: AccountID,
amount: Commodity,
exchange_rate: Option<ExchangeRate>
) -> Transaction
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]
fn date(&self) -> NaiveDate
[src]
fn perform(
&self,
program_state: &mut ProgramState
) -> Result<(), AccountingError>
[src]
&self,
program_state: &mut ProgramState
) -> Result<(), AccountingError>
fn action_type(&self) -> ActionType
[src]
impl Clone for Transaction
[src]
fn clone(&self) -> Transaction
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Debug for Transaction
[src]
impl<'de> Deserialize<'de> for Transaction
[src]
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
impl Display for Transaction
[src]
impl Serialize for Transaction
[src]
Auto Trait Implementations
impl RefUnwindSafe for Transaction
impl Send for Transaction
impl Sync for Transaction
impl Unpin for Transaction
impl UnwindSafe for Transaction
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: Deserialize<'de>,
[src]
T: Deserialize<'de>,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,