Transaction

Struct Transaction 

Source
pub struct Transaction {
Show 14 fields pub id: TransactionId, pub account_id: AccountId, pub date: NaiveDate, pub amount: Money, pub payee_id: Option<PayeeId>, pub payee_name: String, pub category_id: Option<CategoryId>, pub splits: Vec<Split>, pub memo: String, pub status: TransactionStatus, pub transfer_transaction_id: Option<TransactionId>, pub import_id: Option<String>, pub created_at: DateTime<Utc>, pub updated_at: DateTime<Utc>,
}
Expand description

A financial transaction

Fields§

§id: TransactionId

Unique identifier

§account_id: AccountId

The account this transaction belongs to

§date: NaiveDate

Transaction date

§amount: Money

Amount (positive for inflow, negative for outflow)

§payee_id: Option<PayeeId>

Payee ID (optional)

§payee_name: String

Payee name (stored for display, even if payee_id is set)

§category_id: Option<CategoryId>

Category ID (None if this is a split transaction or transfer)

§splits: Vec<Split>

Split transactions - if non-empty, category_id should be None

§memo: String

Memo/notes

§status: TransactionStatus

Transaction status

§transfer_transaction_id: Option<TransactionId>

If this is a transfer, the ID of the linked transaction in the other account

§import_id: Option<String>

Import ID for duplicate detection during CSV import

§created_at: DateTime<Utc>

When the transaction was created

§updated_at: DateTime<Utc>

When the transaction was last modified

Implementations§

Source§

impl Transaction

Source

pub fn new(account_id: AccountId, date: NaiveDate, amount: Money) -> Self

Create a new transaction

Source

pub fn with_details( account_id: AccountId, date: NaiveDate, amount: Money, payee_name: impl Into<String>, category_id: Option<CategoryId>, memo: impl Into<String>, ) -> Self

Create a transaction with all common fields

Source

pub fn is_split(&self) -> bool

Check if this is a split transaction

Source

pub fn is_transfer(&self) -> bool

Check if this is a transfer

Source

pub fn is_inflow(&self) -> bool

Check if this is an inflow (positive amount)

Source

pub fn is_outflow(&self) -> bool

Check if this is an outflow (negative amount)

Source

pub fn is_locked(&self) -> bool

Check if this transaction is locked

Source

pub fn set_status(&mut self, status: TransactionStatus)

Set the status

Source

pub fn clear(&mut self)

Clear the transaction (mark as cleared)

Source

pub fn reconcile(&mut self)

Mark as reconciled

Source

pub fn add_split(&mut self, split: Split)

Add a split

Source

pub fn set_category(&mut self, category_id: CategoryId)

Clear all splits and set a single category

Source

pub fn splits_total(&self) -> Money

Get the total of all splits (should equal transaction amount)

Source

pub fn validate(&self) -> Result<(), TransactionValidationError>

Validate the transaction

Source

pub fn generate_import_id(&self) -> String

Generate an import ID for duplicate detection

Trait Implementations§

Source§

impl Clone for Transaction

Source§

fn clone(&self) -> Transaction

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Transaction

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Transaction

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Transaction

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Serialize for Transaction

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToCompactString for T
where T: Display,

Source§

impl<T> ToLine for T
where T: Display,

Source§

fn to_line(&self) -> Line<'_>

Converts the value to a Line.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToSpan for T
where T: Display,

Source§

fn to_span(&self) -> Span<'_>

Converts the value to a Span.
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T> ToText for T
where T: Display,

Source§

fn to_text(&self) -> Text<'_>

Converts the value to a Text.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

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