Skip to content

Add flag to mark an account as default for its role during creation #296

@ahmersaud

Description

@ahmersaud

Summary

Currently, when creating accounts programmatically (via EntityModel.create_account()), there is no way to mark an account as the default for its role (e.g. cash, receivable, or deferred revenue).

Because of this, when I try to create invoices using entity.create_invoice(), it raises errors saying it cannot find the default cash, receivable, or deferred revenue accounts — even though those accounts exist in the chart of accounts and i also tried passing those accounts to the function which creates invoices.

I can only fix this issue by going into the Django-Ledger admin UI and manually activating the accounts (marking them as default for the role). This manual step makes automation difficult.


Example

Here’s a simplified example of how I’m creating accounts:

entity.create_account(
    coa_model=coa,
    code="1000",
    name="Main Cash Account",
    role=roles.ASSET_CA_CASH,
    balance_type="debit",
    active=True
)

Even though the account is active, the invoice API still throws an error:
AccountModel.DoesNotExist: AccountModel matching query does not exist for role=ASSET_CA_CASH

Only after manually setting it as default in the Django-Ledger UI does the invoice creation work.

Suggested solution

Add a simple boolean parameter to EntityModel.create_account() (for example: is_role_default: bool = False) that allows marking an account as default for its role during creation.

Example usage:

entity.create_account(
    coa_model=coa,
    code="1000",
    name="Main Cash Account",
    role=roles.ASSET_CA_CASH,
    balance_type="debit",
    active=True,
    is_role_default=True
)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions