Account

Standard Accounts

class account.Account[source]

Bases: gnewcash.guid_object.GuidObject, gnewcash.slot.SlottableObject

Represents an account in GnuCash.

as_dict(account_hierarchy: Dict[str, Account] = None, path_to_self: str = '/') → Dict[str, account.Account][source]

Retrieves the current account hierarchy as a dictionary.

Parameters:
  • account_hierarchy (dict) – Existing account hierarchy. If None is provided, assumes a new dictionary.
  • path_to_self (str) – Dictionary key for the current account.
Returns:

Dictionary containing current account and all subaccounts.

Return type:

dict

color

Account color.

Returns:Account color as a string
Return type:str
dict_entry_name

Retrieves the dictionary entry based on account name.

Only alpha-numeric and underscore characters allowed. Spaces and slashes (/) are converted to underscores.

Returns:String with the dictionary entry name.
Return type:str
get_account_guids(account_guids: Optional[List[str]] = None) → List[str][source]

Gets a flat list of account GUIDs under the current account.

Parameters:account_guids (list[str]) – Running list of account GUIDs (should be None on first call)
Returns:List of account GUIDs under the current account
Return type:list[str]
get_parent_commodity() → Optional[gnewcash.commodity.Commodity][source]

Retrieves the commodity for the account.

If none is provided, it will look at it’s parent (and ancestors recursively) to find it.

Returns:Commodity object, or None if no commodity was found in the ancestry chain.
Return type:NoneType|Commodity
get_subaccount_by_id(subaccount_id: str) → Optional[account.Account][source]

Finds a subaccount by its guid field.

Parameters:subaccount_id (str) – Subaccount guid to find
Returns:Account object for that guid or None if no account was found
Return type:NoneType|Account
hidden

Hidden flag for the account.

Returns:True if account is marked hidden, otherwise False.
Return type:bool
notes

User defined notes for the account.

Returns:User-defined notes
Return type:str
parent

Parent account of the current account.

Returns:Account’s parent
Return type:NoneType|Account
placeholder

Placeholder flag for the account.

Returns:True if the account is a placeholder, otherwise False
Return type:bool
class account.AccountType[source]

Enumeration class to indicate the types of accounts available in GnuCash.

Shortcut Accounts

class account.AssetAccount[source]

Bases: account.Account

Shortcut class to create an account with the type set to AccountType.ASSET.

class account.BankAccount[source]

Bases: account.Account

Shortcut class to create an account with the type set to AccountType.BANK.

class account.CreditAccount[source]

Bases: account.Account

Shortcut class to create an account with the type set to AccountType.CREDIT.

class account.EquityAccount[source]

Bases: account.Account

Shortcut class to create an account with the type set to AccountType.EQUITY.

class account.ExpenseAccount[source]

Bases: account.Account

Shortcut class to create an account with the type set to AccountType.EXPENSE.

class account.IncomeAccount[source]

Bases: account.Account

Shortcut class to create an account with the type set to AccountType.INCOME.

class account.LiabilityAccount[source]

Bases: account.Account

Shortcut class to create an account with the type set to AccountType.LIABILITY.

Special Accounts

class account.InterestAccountBase[source]

Abstract class defining the API for Interest accounts.

get_all_payments(skip_additional_payments: bool = False) → List[Tuple[datetime.datetime, decimal.Decimal, decimal.Decimal]][source]

Abstract method for retrieving all payments for the loan plan.

Parameters:skip_additional_payments (bool) – Skips additional payments if True.
get_info_at_date(date: datetime.datetime) → account.LoanStatus[source]

Abstract method for retrieving the loan info at a specified date for the account.

Parameters:date (datetime.datetime) – datetime object indicating the date you want the loan status of
interest_percentage

Abstract method for retrieving the interest percentage for the account.

payment_amount

Abstract method for retrieving the payment amount for the account.

starting_balance

Abstract method for retrieving the starting balance for the account.

starting_date

Abstract method for retrieving the starting date for the account.

class account.InterestAccount(starting_balance: decimal.Decimal, starting_date: datetime.datetime, interest_percentage: decimal.Decimal, payment_amount: decimal.Decimal, additional_payments: Optional[List[account.LoanExtraPayment]] = None, skip_payment_dates: Optional[List[datetime.datetime]] = None, interest_start_date: Optional[datetime.datetime] = None)[source]

Class used to calculate interest balances.

__init__(starting_balance: decimal.Decimal, starting_date: datetime.datetime, interest_percentage: decimal.Decimal, payment_amount: decimal.Decimal, additional_payments: Optional[List[account.LoanExtraPayment]] = None, skip_payment_dates: Optional[List[datetime.datetime]] = None, interest_start_date: Optional[datetime.datetime] = None)[source]

Class initializer.

Parameters:
  • starting_balance (decimal.Decimal|NoneType) – Starting balance for the interest account.
  • starting_date (datetime.datetime|NoneType) – datetime object indicating the date of the starting balance.
  • interest_percentage (decimal.Decimal|NoneType) – Percentage to interest on the loan.
  • payment_amount (decimal.Decimal|NoneType) – Payment amount on the loan.
  • additional_payments (list[LoanExtraPayment]|NoneType) – List of LoanExtraPayment objects indicating extra payments to the loan.
  • skip_payment_dates (list[datetime.datetime]|NoneType) – List of datetime objects that the loan payment should be skipped
  • interest_start_date (datetime.datetime|NoneType) – datetime object that interest starts on
get_all_payments(skip_additional_payments: bool = False) → List[Tuple[datetime.datetime, decimal.Decimal, decimal.Decimal]][source]

Retrieves a list of tuples that show all payments for the loan plan.

Parameters:skip_additional_payments (bool) – Skips additional payments if True.
Returns:List of tuples with the date (index 0), balance (index 1) and amount to capital (index 2)
Return type:list[tuple]
get_info_at_date(date: datetime.datetime) → account.LoanStatus[source]

Retrieves the loan info at a specified date for the current account.

Parameters:date (datetime.datetime) – datetime object indicating the date you want the loan status of
Returns:LoanStatus object
Return type:LoanStatus
interest_percentage

Retrieves the interest percentage for the account.

Returns:Current InterestAccount object’s percentage.
Return type:decimal.Decimal
payment_amount

Retrieves the payment amount for the account.

Returns:Current InterestAccount object’s payment amount.
Return type:decimal.Decimal
starting_balance

Retrieves the starting balance for the account.

Returns:Current InterestAccount object’s starting balance.
Return type:decimal.Decimal
starting_date

Retrieves the starting date for the account.

Returns:Current InterestAccount’s starting date.
Return type:datetime.datetime
class account.InterestAccountWithSubaccounts(subaccounts: List[account.InterestAccount], additional_payments: Optional[List[Dict[str, Union[decimal.Decimal, datetime.datetime]]]] = None, skip_payment_dates: Optional[List[datetime.datetime]] = None)[source]

Class used to calculate interest balances based off of balances of subaccounts.

__init__(subaccounts: List[account.InterestAccount], additional_payments: Optional[List[Dict[str, Union[decimal.Decimal, datetime.datetime]]]] = None, skip_payment_dates: Optional[List[datetime.datetime]] = None)[source]

Class initializer.

Parameters:
  • subaccounts (list[InterestAccount]) – List of InterestAccount objects that are subaccounts of this InterestAccount
  • additional_payments (list[dict]|NoneType) – List of dictionaries containing an “amount” key for additional amount paid, and “payment_date” for the date the additional amount was paid.
  • skip_payment_dates (list[datetime.datetime]|NoneType) – List of datetime objects that the loan payment should be skipped
get_all_payments(skip_additional_payments: bool = False) → List[Tuple[datetime.datetime, decimal.Decimal, decimal.Decimal]][source]

Retrieves a list of tuples that show all payments for the loan plan.

Parameters:skip_additional_payments (bool) – Skips additional payments if True.
Returns:List of tuples with the date (index 0), balance (index 1) and amount to capital (index 2)
Return type:list[tuple]
get_info_at_date(date: datetime.datetime) → account.LoanStatus[source]

Retrieves the loan info at a specified date for all subaccounts.

Parameters:date (datetime.datetime) – datetime object indicating the date you want the loan status of
Returns:LoanStatus object
Return type:LoanStatus
interest_percentage

Retrieves the sum of the subaccounts’ interest percentage.

Returns:Sum of interest percentages.
Return type:decimal.Decimal
payment_amount

Retrieves the sum of the subaccounts’ payment amount.

Returns:Sum of the payment amounts.
Return type:decimal.Decimal
starting_balance

Retrieves the sum of the subaccounts’ starting balance.

Returns:Sum of the starting balances.
Return type:decimal.Decimal
starting_date

Retrieves the minimum starting date of the subaccounts.

Returns:Minimum starting date.
Return type:datetime.datetime
class account.LoanStatus(iterator_balance, iterator_date, interest, amount_to_capital)

Bases: tuple

amount_to_capital

Alias for field number 3

interest

Alias for field number 2

iterator_balance

Alias for field number 0

iterator_date

Alias for field number 1

class account.LoanExtraPayment(payment_date, payment_amount)

Bases: tuple

payment_amount

Alias for field number 1

payment_date

Alias for field number 0