accounts Package

models Module

class accounts.models.Account(*args, **kwargs)[source]

Holds information on Accounts.

get_balance()[source]

Returns the value balance for the Account.

The Account model stores the credit/debit balance in the balance field. This method will convert the credit/debit balance to a value balance for Account.type where a debit increases the Account's value, instead of decreasing it(the normal action).

The Current Year Earnings Account does not source it’s balance field but instead uses the Sum of all Accounts with type of 4 to 8.

See also

flip_balance() method for more information on value balances.

Returns:The Account’s current value balance.
Return type:decimal.Decimal
get_balance_by_date[source]

Calculate the Account's balance at the end of a specific date.

For the Current Year Earnings Account, Transactions from all Accounts with type of 4 to 8 will be used.

Parameters:date (datetime.date) – The day whose balance should be returned.
Returns:The Account’s balance at the end of the specified date.
Return type:decimal.Decimal
get_balance_change_by_month(date)[source]

Calculates the Accounts net change in balance for the month of the specified date.

For the Current Year Earnings Account, Transactions from all Accounts with type of 4 to 8 will be used.

Parameters:date (datetime.date) – The month to calculate the net change for.
Returns:The Account’s net balance change for the specified month.
Return type:decimal.Decimal
class accounts.models.BaseAccountModel(*args, **kwargs)[source]

Abstract class storing common attributes of Headers and Accounts.

Subclasses must implement the _calculate_full_number and _get_change_tree methods.

clean()[source]

Set the type and calculate the full_number.

The type attribute will be inherited from the parent and the full_number will be calculated if the object has an id.

delete(*args, **kwargs)[source]

Renumber Headers or Accounts when deleted.

get_full_number()[source]

Retrieve the Full Number from the model field.

save(*args, **kwargs)[source]

Resave Headers or Accounts if the parent has changed.

This method first checks to see if the parent attribute has changed. If so, it will cause the object and all related objects(the change_tree) to be saved once the pending changes have been saved.

class accounts.models.Header(*args, **kwargs)[source]

Groups Accounts Together.

get_account_balance()[source]

Traverse child Headers and Accounts to generate the current balance.

Returns:The Value Balance of all Accounts and Headers under this Header.
Return type:decimal.Decimal
class accounts.models.HistoricalAccount(*args, **kwargs)[source]

A model for Archiving Historical Account Data. It stores an Account's balance (for Assets, Liabilities and Equities) or net_change (for Incomes and Expenses) for a certain month in a previous Fiscal Years.

Hard data is stored in additon to a link back to the originating Account.

Note

This model is automatically generated by the add_fiscal_year() view.

Note

This model does not inherit from the BaseAccountModel because it has no parent attribute and cannot inherit from MPTTModel.

account

The Account this HistoricalAccount was generated for. The HistoricalAccount will remain even if the Account is deleted.

number

The Account number, formatted as type-num must be unique with respect to date.

name

The Account’s name, must be unique with respect to date.

type

The Account’s type, chosen from TYPE_CHOICES.

amount

The end-of-month balance for HistoricalAccounts with type 1-3, and the net change for HistoricalAccounts with type 4-8. This field represents the credit/debit amount not the value amount. To retrieve the value amount for a HistoricalAccount use the get_amount() method.

date

A datetime.date object representing the 1st day of the Month and Year the archive was created.

flip_balance[source]

Determines whether the HistoricalAccount.amount should be flipped based on the HistoricalAccount.type.

For example, debits(negative HistoricalAccount.amount) increase the value of Assets, Expenses, Cost of Sales and Other Expenses, while decreasing the value of all other Account Types.

In essence, this method will return True if the credit/debit amount needs to be negated(multiplied by -1) to display the value amount, and False if the credit/debit amount is the displayable value amount.

get_absolute_url(*moreargs, **morekwargs)[source]

The default URL for a HistoricalAccount points to the listing for the date's month and year.

get_amount[source]

Calculates the flipped/value balance or net_change for Asset, Cost of Sales, Expense and Other Expense HistoricalAccounts.

The amount field for HistoricalAccounts represents the credit/debit amounts but debits for Asset, Cost of Sales, Expense and Other Expenses represent a positive value instead of a negative value. This function returns the value amount of these accounts instead of the debit/credit amount. E.g., a negative(debit) amount will be returned as a positive value amount.

If the HistoricalAccount is not one of these types, the HistoricalAccounts normal amount will be returned.

Returns:The value amount for the HistoricalAccount
Return type:decimal.Decimal

managers Module

class accounts.managers.AccountManager[source]

A Custom Manager for the Account Model.

This class inherits from the CachingTreeManager.

active()[source]

This method will return a Querset containing all Active Accounts.

get_banks()[source]

This method will return a Queryset containing any Bank Accounts.

forms Module

views Module

accounts.views.accounts_query(request, *args, **kwargs)[source]

AJAX endpoint for querying Account Names & Descriptions.

Returns an array of JSON objects that contain the GET parameter q in their name or description. Each object has a text, value & description property. Defaults to all Account if q is not present in the GET parameters.

Processes search for quick_account tag

Processes search for bank journals

accounts.views.reconcile_account(request, *args, **kwargs)[source]

Reconcile an Account against a Statement.

This view presents a form to the user, allowing them to enter a Statement Balance and Statement Date. Upon a GET request with valid data, the view will display all unreconciled Transactions from before the entered Statement Date.

The user will then select which Transactions to reconcile. If a balanced form is submit, the view will mark each marked Transaction as reconciled. The user will then be redirected to the Account's show_account_detail() view.

Parameters:
  • account_slug (str) – The slug of the Account to reconcile.
  • template_name (str) – The template to use.
Returns:

HTTP response containing AccountReconcileForm, ReconcileTransactionFormSet, the Account, and the Reconciled Balance and Last Reconciled Date as context. Redirects if successful POST is sent.

Return type:

HttpResponse or HttpResponseRedirect

accounts.views.show_account_detail(request, account_slug, template_name='accounts/account_detail.html')[source]

Displays a list of Transaction instances for the Account with a slug equal to the account_slug parameter.

The following GET parameters are accessible:
  • start_date - The starting date to filter the returned Transactions by.
  • stop_date - The ending date to filter the returned Transactions by.

The start_date and stop_date variables default to the first day of the month and the current date.

The view will provide start_balance, end_balance, transactions, debit_total, credit_total and net_change context variables. The Transactions in the context variable transactions will have the running balance added to the instance through the final_balance attribute.

If the provided start_date is before the start of the current FiscalYear, the running balance and Transaction's final_balance will not be calculated.

If there are no Transactions the start_balance and end_balance will both be set to the balance on the start_date

Parameters:
  • account_slug (str) – The slug of top Account to retrieve.
  • template_name (str) – The template file to use to render the response.
Returns:

HTTP Response with Transactions and balance counters.

Return type:

HttpResponse

accounts.views.show_account_history(request, month=None, year=None, template_name='accounts/account_history.html')[source]

Displays a list of HistoricalAccount instances, grouped by the optional month and year.

By default a list of the instances from this month of last year will be returned. If those instances do not exist, the most recent month/year list will be displayed.

If no instances of accounts.models.HistoricalAccount exist, an empty string will be returned.

The following GET parameters are accessible:
  • next - Use the next month relative to the passed month and year values. Redirects back to passed month and year if no Historical Accounts exist.
  • previous - Use the previous month relative to the passed month and year values. Redirects back to passed month and year if no Historical Accounts exist.
Parameters:
  • month (int) – The Month to select, usage requires a specified year.
  • year (int) – The Year to select, usage requires a specified month.
  • template_name (string) – The template to use.
Returns:

HTTP context with a list of instances or empty string as accounts and a date as date

Return type:

HttpResponse

Raises Http404:

if an invalid month or year is specified.

accounts.views.show_accounts_chart(request, header_slug=None, template_name='accounts/account_charts.html')[source]

Retrieves self and descendant Headers or all Headers

signals Module

accounts.signals.transaction_delete(sender, instance, **kwargs)[source]

Refund Transaction before deleting from database.

accounts.signals.transaction_postsave(sender, instance, **kwargs)[source]

Change Account Balance on Save.

accounts.signals.transaction_presave(sender, instance, **kwargs)[source]

Refund Account balances if updating a Transaction.