The Document class

class document.Document(view, app)

The Document is the core class of moneyGuru. It represents a new or opened document and holds all model instances associated to it (accounts, transactions, etc.). The Document is also responsible for notifying all gui instances of changes. While it’s OK for GUI instances to directly access models (through Document.transactions and Document.accounts, for example), any modification to those models have to go through Document‘s public methods.

Another important role of the Document is to manage undo points. For undo to work properly, every mutative action must be properly recorded, and that’s what the Document does.

When calling methods that take “hard values” (dates, descriptions, etc..), it is expected that these values have already been parsed (it’s the role of the GUI instances to parse data). So dates are datetime.date instances, amounts are Amount instances, indexes are int.

Account-related methods

change_account(account[, name=NOEDIT, type=NOEDIT, currency=NOEDIT, group=NOEDIT, account_number=NOEDIT])

Sets account‘s properties in a proper manner and post a account_changed notification. Attributes corresponding to arguments set to NOEDIT will not be touched.

Parameters:
  • accountAccount
  • namestr
  • typeAccountType
  • currencyCurrency
  • groupGroup
  • account_numberstr
delete_selected_account()

Removes the current selected_account from the account list. If the account has entries assigned to it, account_needs_reassignment will be posted, which makes the account reassignment panel pop up (the panel will then call reassign_and_delete_selected_account()).

new_account(type, group)

Creates a new account of type type, within the group (which can be None). The new account will have a unique name based on the string “New Account” (if it exists, a unique number will be appended to it). Once created, the account is added to the account list, and account_added is broadcasted.

Parameters:
  • typeAccountType
  • groupGroup
Return type:

Account

toggle_accounts_exclusion(accounts)

Toggles the excluded state (in sheets, when accounts ar grayed out) of accounts. Afterwards, accounts_excluded is broadcasted.

Parameters:accounts – a set of Account

Group-related methods

change_group(group[, name=NOEDIT])

Sets group‘s properties in a proper manner and post a account_changed notification. Attributes corresponding to arguments set to NOEDIT will not be touched.

Parameters:
  • groupGroup
  • namestr
delete_group(group)

Removes group from the group list and broadcasts account_deleted. All accounts belonging to the deleted group have their Account.group attribute set to None.

Parameters:groupGroup
new_group(type)

Creates a new group of type type (an AccountType). The new group will have a unique name based on the string “New Group” (if it exists, a unique number will be appended to it). Once created, the group is added to the group list, and account_added is broadcasted.

Parameters:typeAccountType
Return type:Group

Transaction-related methods

can_move_transactions(transactions, before, after)

Returns whether transactions can be be moved (re-ordered). Transactions can only be moved when all transactions are of the same date, and that the date of those transaction is between the date of before and after. When before or after is None, it means that it’s the end or beginning of the list.

Parameters:
  • transactions – a collection of Transaction
  • beforeTransaction
  • afterTransaction
Return type:

bool

change_transaction(original, new)

Changes the attributes of original so that they match those of new. This is used by the TransactionPanel, and new is originally a copy of original which has been changed. Accounts linked to splits in new don’t have to be accounts that are part of the document. This method will automatically internalize accounts linked to splits (and create new accounts if necessary).

If new‘s date is outside of the current date range, the date range will automatically be changed so that it contains new.

If original is a schedule Spawn, the UI will be queried for a scope, which might result in the change being aborted.

After the transaction change, transaction_changed is broadcasted.

Parameters:
  • originalTransaction
  • newTransaction
change_transactions(transactions[, date=NOEDIT, description=NOEDIT, payee=NOEDIT, checkno=NOEDIT, from_=NOEDIT, to=NOEDIT, amount=NOEDIT, currency=NOEDIT])

Changes the attributes of every transaction in transactions to the values specified in the arguments (arguments left to NOEDIT have no effect).

from_ and to are account names rather than being Account instances. If the names don’t exist, they’ll automatically be created.

If any transaction in transactions is a schedule Spawn, the UI will be queried for a scope, which might result in the change being aborted.

After the transaction change, transaction_changed is broadcasted.

Parameters:
  • datedatetime.date
  • descriptionstr
  • payeestr
  • checknostr
  • fromstr
  • tostr
  • amountAmount
  • currencyCurrency
delete_transactions(transactions)

Removes every transaction in transactions from the document.

If any transaction in transactions is a schedule Spawn, the UI will be queried for a scope, which might result in the deletion being aborted.

After the transaction deletion, transaction_deleted is broadcasted.

Parameters:transactions – a collection of Transaction
duplicate_transactions(transactions)

For each transaction in transactions, add a new transaction with the same attributes to the document.

After the operation, transaction_changed is broadcasted.

Parameters:transactions – a collection of Transaction
move_transactions(transactions, to_transaction)

Re-orders transactions so that they are right before to_transaction. If to_transaction is None, it means that we move transactions at the end of the list.

Make sure your move is legal by calling can_move_transactions() first.

After the move, transaction_changed is broadcasted.

Parameters:
  • transactions – a collection of Transaction
  • to_transactionTransaction

Entry-related methods

change_entry(entry[, date=NOEDIT, reconciliation_date=NOEDIT, description=NOEDIT, payee=NOEDIT, checkno=NOEDIT, transfer=NOEDIT, amount=NOEDIT])

Changes the attributes of entry (and the transaction in which entry is) to specified values and then post a transaction_changed notification. Attributes with NOEDIT values are not touched.

transfer is the name of the transfer to assign the entry to. If it’s not found, a new account will be created.

Parameters:
  • entryEntry
  • datedatetime.date
  • reconciliation_datedatetime.date
  • descriptionstr
  • payeestr
  • checknostr
  • transferstr
  • amountAmount
delete_entries(entries)

Remove transactions in which entries belong from the document’s transaction list.

Parameters:entries – list of Entry
toggle_entries_reconciled(entries)

Toggles the reconciliation flag (sets the reconciliation_date to the entry’s date, or unset it when turning the flag off) of entries.

Parameters:entries – list of Entry

Budget-related methods

budgeted_amount_for_target(target, date_range)

Returns the amount budgeted for all budgets targeting target. The amount is pro-rated according to date_range.

Parameters:
  • targetAccount
  • date_rangeDateRange
change_budget(original, new)

Changes the attributes of original so that they match those of new. This is used by the BudgetPanel, and new is originally a copy of original which has been changed.

Parameters:
  • originalBudget
  • newBudget
delete_budgets(budgets)

Removes budgets from the document.

Parameters:budgets – list of Budget

Schedule-related methods

change_schedule(schedule, new_ref, repeat_type, repeat_every, stop_date)

Change attributes of schedule. new_ref is a reference transaction that the schedule is going to repeat.

Parameters:
  • scheduleSchedule
  • new_refTransaction
  • repeat_typeRepeatType
  • stop_datedatetime.date
delete_schedules(schedules)

Removes schedules from the document.

Parameters:schedules – list of Schedule

Load/Save/Import methods

adjust_example_file()

Adjusts all document’s transactions so that they become current. This is used when loading the example document so that it’s not necessary to do it manually.

clear()

Removes all data from the document (transactions, accounts, schedules, etc.).

load_from_xml(filename)

Clears the document and loads data from filename, which must be a path to a moneyGuru XML document.

Parameters:filenamestr
save_to_xml(filename[, autosave=False])

Saves the document to filename in moneyGuru’s XML document format. If autosave is true, the operation will not affect the document’s modified state and will not make editing stop, if editing there is (like it normally does without the autosave flag to make sure that the input being currently done by the user is saved).

Parameters:
  • filenamestr
  • autosavebool
save_to_qif(filename)

Saves the document to filename in the QIF format.

Parameters:filenamestr
parse_file_for_import(filename)

Opens and parses filename and try to determine its format by successively trying to read is as a moneyGuru file, an OFX, a QIF and finally a CSV. Once parsed, take the appropriate action for the file which is either to show the CSV options window or to call load_parsed_file_for_import()

load_parsed_file_for_import()

When the document’s loader has finished parsing (either after having done CSV configuration or directly after parse_file_for_import()), call this method to load the parsed data into model instances, ready to be shown in the Import window.

import_entries(target_account, ref_account, matches)

Imports entries in mathes into target_account. target_account can be either an existing account in the document or not. ref_account is a reference to the temporary Account created by the loader.

matches is a list of tuples (entry, ref) with entry being the entry being imported and ref being an existing entry in the target_account bound to entry. ref can be None and it’s only possible to have a ref side when the target account already exists in the document.

is_dirty()

Returns whether the document has been modified since the last time it was saved.

Date Range

select_month_range(starting_point)
select_quarter_range(starting_point)
select_year_range(starting_point)
select_year_to_date_range()
select_running_year_range()
select_all_transactions_range()

Sets the document’s date range to the date range corresponding to the method called. For navigable date ranges, a starting_point has to be given, which can be either a date or a date range. The resulting date range will contain the starting point (or its start date, if it’s a date range).

select_custom_date_range([start_date, end_date])

Sets the document’s date range to a range with arbirtrary start and end dates. If these dates are not given, the document will send a notification for the custom date range panel to show up.

select_prev_date_range()
select_next_date_range()

If the current date range is navigable, select the date range coming before/after the current one.

select_today_date_range()

If the current date range is navigable, select a date range that contains today’s date.

date_range

The currently selected date range for the document.

Undo/Redo

can_undo()
can_redo()

Returns wether the document has something to undo or redo.

undo_description()
redo_description()

Returns a string describing the action that would be undone or redone if undo() or redo() was called.

undo()

Undo the last undoable action.

redo()

Redo the last undone action.

Misc

close()

Saves preferences and tells GUI elements about the document closing (so that they can save their own preferences if needed).

stop_edition()

Tells GUI elements to stop editing. Some actions create glitches if they are done while a table/outline is being edited, so it’s necessary to stop editing before that action is done.

filter_string

When set to an non empty string, it restricts visible transactions/entries in TransactionTable and EntryTable to those matching with the string.

filter_type

When set to something else than None, it restricts visible transactions in TransactionTable and EntryTable to those matching the FilterType set.

document.FilterType

A class in which available filter constants are defined: Unassigned, Income, Expense, Transfer, Reconciled and NotReconciled.

Previous topic

moneyGuru API

This Page