diff options
| author | Danilo M. <danix@danix.xyz> | 2026-06-30 13:07:06 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-06-30 13:07:06 +0200 |
| commit | 93dbbe18e934d87ebf6ae6c614bb26f0e9e5afa5 (patch) | |
| tree | 73770fb498e16103528bdd350d9159d3ead170aa /firefly_cli/commands/account.py | |
| parent | 2db11aa5d34766e4d23ccc308c57c470b6aa6dba (diff) | |
| download | firefly-cli-be8342569e25b72af39a9b797613b8ac0633819d.tar.gz firefly-cli-be8342569e25b72af39a9b797613b8ac0633819d.zip | |
account create: add verb for asset/expense/revenue accountsv0.2.0
New `firefly account create <name> --type asset|expense|revenue`
[--opening-balance N] [--currency CODE]. asset accounts default to
the defaultAsset role; opening balance is dated today (Firefly pairs
the two). Unsupported types (liability, etc.) are a hard client-side
error with no API call. Live-verified against the test instance.
Bumps to 0.2.0. Docs synced: README, CLAUDE.md, SKILL.md, including
the category/tag auto-create clarification.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Diffstat (limited to 'firefly_cli/commands/account.py')
| -rw-r--r-- | firefly_cli/commands/account.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/firefly_cli/commands/account.py b/firefly_cli/commands/account.py index fa2dc65..0e86b2b 100644 --- a/firefly_cli/commands/account.py +++ b/firefly_cli/commands/account.py @@ -1,5 +1,10 @@ # Copyright (C) 2026 Danilo M. <danix@danix.xyz> GPL-2.0-only from firefly_cli import registry, output +from firefly_cli.errors import FireflyError + +# v1 scope: the everyday types. Liabilities need extra required fields +# (liability_type/direction/amount); add when needed. +_CREATE_TYPES = ("asset", "expense", "revenue") def _list_args(p): p.add_argument("--type", help="filter: asset, expense, revenue, liability, ...") @@ -11,6 +16,33 @@ def cmd_list(args, ctx): output.emit(output.unwrap(resp), human=ctx.human) return 0 +def _create_args(p): + p.add_argument("name", help="account name (must be unique)") + p.add_argument("--type", required=True, + help="asset, expense, or revenue") + p.add_argument("--opening-balance", dest="opening_balance", default=None, + help="initial balance (asset accounts); dated today") + p.add_argument("--currency", default=None, help="currency code, e.g. EUR") + +@registry.command("account create", help="create an account", args=_create_args) +def cmd_create(args, ctx): + if args.type not in _CREATE_TYPES: + raise FireflyError( + f'Unsupported account type "{args.type}". ' + f'Use one of: {", ".join(_CREATE_TYPES)}.') + body = {"name": args.name, "type": args.type} + if args.type == "asset": + body["account_role"] = "defaultAsset" + if args.opening_balance is not None: + from datetime import date as _date + body["opening_balance"] = str(args.opening_balance) + body["opening_balance_date"] = _date.today().isoformat() + if args.currency: + body["currency_code"] = args.currency + resp = ctx.client.request("POST", "/api/v1/accounts", body=body) + output.emit(output.unwrap(resp), human=ctx.human) + return 0 + def _name_arg(p): p.add_argument("account", help="account name or id") |
