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: TransactionIdUnique identifier
account_id: AccountIdThe account this transaction belongs to
date: NaiveDateTransaction date
amount: MoneyAmount (positive for inflow, negative for outflow)
payee_id: Option<PayeeId>Payee ID (optional)
payee_name: StringPayee 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: StringMemo/notes
status: TransactionStatusTransaction 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
impl Transaction
Sourcepub fn new(account_id: AccountId, date: NaiveDate, amount: Money) -> Self
pub fn new(account_id: AccountId, date: NaiveDate, amount: Money) -> Self
Create a new transaction
Sourcepub fn with_details(
account_id: AccountId,
date: NaiveDate,
amount: Money,
payee_name: impl Into<String>,
category_id: Option<CategoryId>,
memo: impl Into<String>,
) -> Self
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
Sourcepub fn is_transfer(&self) -> bool
pub fn is_transfer(&self) -> bool
Check if this is a transfer
Sourcepub fn is_outflow(&self) -> bool
pub fn is_outflow(&self) -> bool
Check if this is an outflow (negative amount)
Sourcepub fn set_status(&mut self, status: TransactionStatus)
pub fn set_status(&mut self, status: TransactionStatus)
Set the status
Sourcepub fn set_category(&mut self, category_id: CategoryId)
pub fn set_category(&mut self, category_id: CategoryId)
Clear all splits and set a single category
Sourcepub fn splits_total(&self) -> Money
pub fn splits_total(&self) -> Money
Get the total of all splits (should equal transaction amount)
Sourcepub fn validate(&self) -> Result<(), TransactionValidationError>
pub fn validate(&self) -> Result<(), TransactionValidationError>
Validate the transaction
Sourcepub fn generate_import_id(&self) -> String
pub fn generate_import_id(&self) -> String
Generate an import ID for duplicate detection
Trait Implementations§
Source§impl Clone for Transaction
impl Clone for Transaction
Source§fn clone(&self) -> Transaction
fn clone(&self) -> Transaction
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Transaction
impl Debug for Transaction
Source§impl<'de> Deserialize<'de> for Transaction
impl<'de> Deserialize<'de> for Transaction
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Display for Transaction
impl Display for Transaction
Auto Trait Implementations§
impl Freeze for Transaction
impl RefUnwindSafe for Transaction
impl Send for Transaction
impl Sync for Transaction
impl Unpin for Transaction
impl UnwindSafe for Transaction
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString. Read more