Core Components
Account Headings
- class AccountHeading
A classification system for accounts that defines their type and behavior.
Fields:
heading(CharField): The name of the headingheading_type(CharField): Type of the account (choices defined in ACCOUNT_TYPE)balance_type(CharField): Balance type, either “dr” (Debit) or “cr” (Credit)number(IntegerField): Heading number for ordering/referencetracker(IntegerField): Tracks changes/versions of the heading
Accounts
- class Account
Represents individual accounts in the accounting system. Supports hierarchical structure with parent-child relationships.
Fields:
name(CharField): Account nameis_control_account(BooleanField): Indicates if this is a control accountis_active(BooleanField): Account statusheading(ForeignKey): Reference to AccountHeadingnumber(CharField): Account number/codeparent(ForeignKey): Reference to parent account (self-referential)
Key Methods:
- period_records(end, extra_filters=None)
Retrieves accounting entries for a specific period.
- Parameters:
end – End date for the period
extra_filters – Additional filtering criteria
- Returns:
QuerySet of accounting entries
- period_total(field, end, extra_filters=None)
Calculates total value of entries up to specified end date.
- Parameters:
field – Field to total (‘dr_amount’ or ‘cr_amount’)
end – End date for calculation
extra_filters – Additional filtering criteria
- Returns:
Decimal total value
- balance(end=None, extra_filters=None, dr_filters=None, cr_filters=None)
Calculates account balance at a given date.
- Parameters:
end – End date for balance calculation
extra_filters – General filtering criteria
dr_filters – Filters specific to debit entries
cr_filters – Filters specific to credit entries
- Returns:
Decimal balance value
Accounting Transactions
- class AccountingTransaction
Represents a complete double-entry transaction with balanced debit and credit entries.
Fields:
description(TextField): Transaction descriptiondr_entry(AccountingEntry): Debit entrycr_entry(AccountingEntry): Credit entry
Key Methods:
- validate_entries_value()
Ensures that transaction entries balance according to double-entry principles.
- save(*args, **kwargs)
Saves transaction and associated entries atomically.
Accounting Entries
- class AccountingEntry
Individual ledger entries that make up transactions.
Fields:
account(ForeignKey): Reference to Accounttransaction(ForeignKey): Reference to AccountingTransactiondr_amount(DecimalField): Debit amountcr_amount(DecimalField): Credit amountentry_date(DateTimeField): Date of entrycurrency(ForeignKey): Reference to Currencydescription(CharField): Entry description
Properties:
- property dr_value
Calculated debit value in default currency
- property cr_value
Calculated credit value in default currency
- property amount
Total amount in default currency
Usage Example
# Create a transaction with balanced entries
transaction = AccountingTransaction(
description="Monthly rent payment",
dr_entry=AccountingEntry(
account=rent_expense_account,
dr_amount=1000.00,
currency=usd_currency
),
cr_entry=AccountingEntry(
account=bank_account,
cr_amount=1000.00,
currency=usd_currency
)
)
transaction.save() # This will save both the transaction and its entries
Important Notes
All transactions must follow double-entry principles (debits must equal credits)
Entries must be either debit OR credit, not both
All monetary values are stored with 4 decimal places
Currency conversion is handled automatically based on currency conversion rates
Control accounts aggregate entries from their child accounts