journal
Module for accounting journal and entries.
Classes:
-
CompoundEntry
–Represent a compound journal entry that can affect multiple accounts.
-
Journal
–Class to record all journal entries.
-
JournalEntry
–Abstract base class for a journal entry.
-
SimpleEntry
–Represent a simple journal entry with debit and credit accounts and a value.
CompoundEntry
dataclass
CompoundEntry(
debit_accounts: dict[TAccount, float],
credit_accounts: dict[TAccount, float],
date: date | None = None,
description: str = "",
)
Bases: JournalEntry
Represent a compound journal entry that can affect multiple accounts.
Methods:
-
credit_account_value_pairs
–Return an iterator over credit account and value pairs.
-
debit_account_value_pairs
–Return an iterator over debit account and value pairs.
-
involves_account
–Check if the journal entry involves a specific account.
-
is_balanced
–Check if the compound entry is balanced.
-
to_html
–Return a string representation of the simple journal entry.
-
total_credits
–Calculate the total credits for the compound entry.
-
total_debits
–Calculate the total debits for the compound entry.
-
validate
–Assert sum of debit entries equals sum of credit entries.
credit_account_value_pairs
credit_account_value_pairs() -> (
Iterator[tuple[TAccount, float]]
)
Return an iterator over credit account and value pairs.
debit_account_value_pairs
debit_account_value_pairs() -> (
Iterator[tuple[TAccount, float]]
)
Return an iterator over debit account and value pairs.
involves_account
involves_account(account: TAccount) -> bool
Check if the journal entry involves a specific account.
is_balanced
is_balanced() -> bool
Check if the compound entry is balanced.
Using 1e-6 as a tolerance level to account for floating-point inaccuracies.
to_html
to_html() -> str
Return a string representation of the simple journal entry.
total_credits
total_credits() -> float
Calculate the total credits for the compound entry.
total_debits
total_debits() -> float
Calculate the total debits for the compound entry.
validate
validate() -> None
Assert sum of debit entries equals sum of credit entries.
Journal
dataclass
Journal(entries: list[JournalEntry] = list())
Class to record all journal entries.
Methods:
-
add_entry
–Add a journal entry to the journal.
-
get_entries_by_account
–Get all journal entries involving a specific account.
-
get_entries_by_date
–Get all journal entries for a specific date.
-
get_entries_by_description
–Get all journal entries matching a specific description.
-
get_entries_within_date_range
–Get all journal entries within a specific date range.
-
remove_entry
–Remove a specific journal entry.
get_entries_by_account
get_entries_by_account(
account: TAccount,
) -> list[JournalEntry]
Get all journal entries involving a specific account.
get_entries_by_date
get_entries_by_date(date: date) -> list[JournalEntry]
Get all journal entries for a specific date.
get_entries_by_description
get_entries_by_description(
description: str,
) -> list[JournalEntry]
Get all journal entries matching a specific description.
get_entries_within_date_range
get_entries_within_date_range(
start_date: date, end_date: date
) -> list[JournalEntry]
Get all journal entries within a specific date range.
JournalEntry
Bases: ABC
Abstract base class for a journal entry.
Methods:
-
credit_account_value_pairs
–Return an iterator over credit account and value pairs.
-
debit_account_value_pairs
–Return an iterator over debit account and value pairs.
-
involves_account
–Check if the journal entry involves a specific account.
credit_account_value_pairs
credit_account_value_pairs() -> (
Iterator[tuple[TAccount, float]]
)
Return an iterator over credit account and value pairs.
debit_account_value_pairs
debit_account_value_pairs() -> (
Iterator[tuple[TAccount, float]]
)
Return an iterator over debit account and value pairs.
involves_account
abstractmethod
involves_account(account: TAccount) -> bool
Check if the journal entry involves a specific account.
SimpleEntry
dataclass
SimpleEntry(
debit_account: TAccount,
credit_account: TAccount,
value: float,
date: date | None = None,
description: str = "",
)
Bases: JournalEntry
Represent a simple journal entry with debit and credit accounts and a value.
Methods:
-
credit_account_value_pairs
–Return an iterator over credit account and value pairs.
-
debit_account_value_pairs
–Return an iterator over debit account and value pairs.
-
involves_account
–Check if the journal entry involves a specific account.
-
to_html
–Return a string representation of the simple journal entry.
credit_account_value_pairs
credit_account_value_pairs() -> (
Iterator[tuple[TAccount, float]]
)
Return an iterator over credit account and value pairs.
debit_account_value_pairs
debit_account_value_pairs() -> (
Iterator[tuple[TAccount, float]]
)
Return an iterator over debit account and value pairs.
involves_account
involves_account(account: TAccount) -> bool
Check if the journal entry involves a specific account.
to_html
to_html() -> str
Return a string representation of the simple journal entry.