-
Notifications
You must be signed in to change notification settings - Fork 293
Description
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
)