Data Models¶
The models module contains essential data structures used in the Firefly III Synchronization Tool. This module defines the Account and Transaction classes, which model the financial data handled by the application.
Account¶
The Account class represents a financial account. It includes various attributes such as account type, balance, currency, and other relevant details.
- class models.Account(name: str, account_type: str = 'asset', account_id: int = None, created_at: str = None, updated_at: str = None, active: bool = None, order: int = None, currency_code: str = None, currency_symbol: str = None, currency_decimal_places: int = None, current_balance: float = 0, current_balance_date: str = None, notes: str = None, monthly_payment_date: str = None, credit_card_type: str = None, account_number: str = None, iban: str = None, bic: str = None, virtual_balance: float = None, opening_balance: float = None, opening_balance_date: str = None, liability_type: str = None, liability_direction: str = None, interest: float = None, interest_period: str = None, current_debt: float = None, include_net_worth: bool = None, longitude: float = None, latitude: float = None, zoom_level: int = None)¶
Represents a financial account.
- name¶
The name of the account.
- Type:
str
- account_type¶
The type of the account. Defaults to “asset”.
- Type:
str, optional
- account_id¶
The ID of the account.
- Type:
int, optional
- created_at¶
The creation date of the account.
- Type:
str, optional
- updated_at¶
The last update date of the account.
- Type:
str, optional
- active¶
Indicates if the account is active.
- Type:
bool, optional
- order¶
The order of the account.
- Type:
int, optional
- currency_code¶
The currency code of the account.
- Type:
str, optional
- currency_symbol¶
The currency symbol of the account.
- Type:
str, optional
- currency_decimal_places¶
The number of decimal places for the currency.
- Type:
int, optional
- current_balance¶
The current balance of the account. Defaults to 0.
- Type:
float, optional
- current_balance_date¶
The date of the current balance.
- Type:
str, optional
- notes¶
Additional notes for the account.
- Type:
str, optional
- monthly_payment_date¶
The date of the monthly payment.
- Type:
str, optional
- credit_card_type¶
The type of credit card.
- Type:
str, optional
- account_number¶
The account number.
- Type:
str, optional
- iban¶
The International Bank Account Number (IBAN).
- Type:
str, optional
- bic¶
The Bank Identifier Code (BIC).
- Type:
str, optional
- virtual_balance¶
The virtual balance of the account.
- Type:
float, optional
- opening_balance¶
The opening balance of the account.
- Type:
float, optional
- opening_balance_date¶
The date of the opening balance.
- Type:
str, optional
- liability_type¶
The type of liability.
- Type:
str, optional
- liability_direction¶
The direction of the liability.
- Type:
str, optional
- interest¶
The interest rate of the account.
- Type:
float, optional
- interest_period¶
The period of interest calculation.
- Type:
str, optional
- current_debt¶
The current debt of the account.
- Type:
float, optional
- include_net_worth¶
Indicates if the account is included in net worth calculations.
- Type:
bool, optional
- longitude¶
The longitude coordinate of the account.
- Type:
float, optional
- latitude¶
The latitude coordinate of the account.
- Type:
float, optional
- zoom_level¶
The zoom level of the account.
- Type:
int, optional
Transaction¶
The Transaction class represents a financial transaction. It includes details like the transaction date, amount, type (deposit, withdrawal, transfer), and related account information.
- class models.Transaction(date, amount, type: str = '', description: str = '', transaction_id=None, bill_id=None, bill_name=None, book_date=None, budget_id=None, budget_name=None, bunq_payment_id=None, category_id=None, category_name=None, currency_code=None, currency_decimal_places=None, currency_id=None, currency_name=None, currency_symbol=None, destination_iban=None, destination_id=None, destination_name=None, destination_type=None, due_date=None, external_id=None, external_url=None, foreign_amount=None, foreign_currency_code=None, foreign_currency_decimal_places=None, foreign_currency_id=None, foreign_currency_symbol=None, has_attachments=None, import_hash_v2=None, interest_date=None, internal_reference=None, invoice_date=None, latitude=None, longitude=None, notes=None, order=None, original_source=None, payment_date=None, process_date=None, reconciled=None, recurrence_count=None, recurrence_id=None, recurrence_total=None, sepa_batch_id=None, sepa_cc=None, sepa_ci=None, sepa_country=None, sepa_ct_id=None, sepa_ct_op=None, sepa_db=None, sepa_ep=None, source_iban=None, source_id=None, source_name=None, source_type=None, tags=None, transaction_journal_id=None, user=None, zoom_level=None)¶
Represents a financial transaction.
- Parameters:
date (str or pd.Timestamp) – The date of the transaction.
amount (float) – The amount of the transaction.
type (str, optional) – The type of the transaction. Defaults to “”.
description (str, optional) – The description of the transaction. Defaults to “”.
transaction_id (int, optional) – The ID of the transaction. Defaults to None.
bill_id (int, optional) – The ID of the bill associated with the transaction. Defaults to None.
bill_name (str, optional) – The name of the bill associated with the transaction. Defaults to None.
book_date (str, optional) – The book date of the transaction. Defaults to None.
budget_id (int, optional) – The ID of the budget associated with the transaction. Defaults to None.
budget_name (str, optional) – The name of the budget associated with the transaction. Defaults to None.
bunq_payment_id (int, optional) – The ID of the bunq payment associated with the transaction. Defaults to None.
category_id (int, optional) – The ID of the category associated with the transaction. Defaults to None.
category_name (str, optional) – The name of the category associated with the transaction. Defaults to None.
currency_code (str, optional) – The currency code of the transaction. Defaults to None.
currency_decimal_places (int, optional) – The decimal places of the currency. Defaults to None.
currency_id (int, optional) – The ID of the currency. Defaults to None.
currency_name (str, optional) – The name of the currency. Defaults to None.
currency_symbol (str, optional) – The symbol of the currency. Defaults to None.
destination_iban (str, optional) – The IBAN of the destination. Defaults to None.
destination_id (int, optional) – The ID of the destination. Defaults to None.
destination_name (str, optional) – The name of the destination. Defaults to None.
destination_type (str, optional) – The type of the destination. Defaults to None.
due_date (str, optional) – The due date of the transaction. Defaults to None.
external_id (str, optional) – The external ID of the transaction. Defaults to None.
external_url (str, optional) – The external URL of the transaction. Defaults to None.
foreign_amount (float, optional) – The foreign amount of the transaction. Defaults to None.
foreign_currency_code (str, optional) – The foreign currency code of the transaction. Defaults to None.
foreign_currency_decimal_places (int, optional) – The decimal places of the foreign currency. Defaults to None.
foreign_currency_id (int, optional) – The ID of the foreign currency. Defaults to None.
foreign_currency_symbol (str, optional) – The symbol of the foreign currency. Defaults to None.
has_attachments (bool, optional) – Indicates if the transaction has attachments. Defaults to None.
import_hash_v2 (str, optional) – The import hash of the transaction. Defaults to None.
interest_date (str, optional) – The interest date of the transaction. Defaults to None.
internal_reference (str, optional) – The internal reference of the transaction. Defaults to None.
invoice_date (str, optional) – The invoice date of the transaction. Defaults to None.
latitude (float, optional) – The latitude of the transaction. Defaults to None.
longitude (float, optional) – The longitude of the transaction. Defaults to None.
notes (str, optional) – The notes of the transaction. Defaults to None.
order (int, optional) – The order of the transaction. Defaults to None.
original_source (str, optional) – The original source of the transaction. Defaults to None.
payment_date (str, optional) – The payment date of the transaction. Defaults to None.
process_date (str, optional) – The process date of the transaction. Defaults to None.
reconciled (bool, optional) – Indicates if the transaction is reconciled. Defaults to None.
recurrence_count (int, optional) – The recurrence count of the transaction. Defaults to None.
recurrence_id (int, optional) – The recurrence ID of the transaction. Defaults to None.
recurrence_total (int, optional) – The recurrence total of the transaction. Defaults to None.
sepa_batch_id (int, optional) – The SEPA batch ID of the transaction. Defaults to None.
sepa_cc (str, optional) – The SEPA CC of the transaction. Defaults to None.
sepa_ci (str, optional) – The SEPA CI of the transaction. Defaults to None.
sepa_country (str, optional) – The SEPA country of the transaction. Defaults to None.
sepa_ct_id (str, optional) – The SEPA CT ID of the transaction. Defaults to None.
sepa_ct_op (str, optional) – The SEPA CT OP of the transaction. Defaults to None.
sepa_db (str, optional) – The SEPA DB of the transaction. Defaults to None.
sepa_ep (str, optional) – The SEPA EP of the transaction. Defaults to None.
source_iban (str, optional) – The IBAN of the source. Defaults to None.
source_id (int, optional) – The ID of the source. Defaults to None.
source_name (str, optional) – The name of the source. Defaults to None.
source_type (str, optional) – The type of the source. Defaults to None.
tags (str, optional) – The tags of the transaction. Defaults to None.
transaction_journal_id (int, optional) – The ID of the transaction journal. Defaults to None.
user (str, optional) – The user associated with the transaction. Defaults to None.
zoom_level (int, optional) – The zoom level of the transaction. Defaults to None.
- transaction_id¶
The ID of the transaction.
- Type:
int
- amount¶
The amount of the transaction.
- Type:
float
- type¶
The type of the transaction.
- Type:
str
- description¶
The description of the transaction.
- Type:
str
- date¶
The date of the transaction.
- Type:
datetime.date
- ...
- __str__()¶
Returns a string representation of the transaction.
- __hash__()¶
Returns the hash value of the transaction.
- custom_normalized_score(str1, str2)¶
Calculates the custom normalized score between two strings.
- _rm_date(input_string)¶
Removes the date from the input string.
- _cleaned_description(description)¶
Cleans the description by removing extra repetitions and specific strings.
- _compare_descriptions(other, threshold)¶
Compares the descriptions of two transactions and returns True if they match.
- __eq__(other)¶
Checks if two transactions are equal.
Usage¶
These models are used throughout the application to represent and manipulate financial data. They provide a structured way to handle financial information, facilitating interactions with the Firefly III API and local data processing.
Example:
from models import Account, Transaction
# Creating an account instance
account = Account(name="Checking Account", account_type="asset", current_balance=1000.0)
# Creating a transaction instance
transaction = Transaction(date="2024-01-01", amount=150.0, type="deposit", description="Salary")
These instances can then be used in various parts of the application, such as syncing data with Firefly III, processing local data, or generating reports.