summaryrefslogtreecommitdiffstats
path: root/firefly_cli/commands/account.py
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-07-01 10:29:04 +0200
committerDanilo M. <danix@danix.xyz>2026-07-01 10:29:04 +0200
commitb078c5980facc0ebe4acd1f251f6ae3dad561292 (patch)
tree29611c1d9f039e96db81b4b2bc31b8d7729f0a36 /firefly_cli/commands/account.py
parent0c9939c5961a3cef50e6378c0eefbeaae00f4c67 (diff)
downloadfirefly-cli-b078c5980facc0ebe4acd1f251f6ae3dad561292.tar.gz
firefly-cli-b078c5980facc0ebe4acd1f251f6ae3dad561292.zip
feat: account balance --at for historical balance (v0.3.2)
Reconciliation needed an account's balance as of a past date; the command only reported the current balance, forcing hand-written sum scripts. --at YYYY-MM-DD re-fetches the account with Firefly's ?date= param, which recomputes current_balance as of that date (end of day, no client math). Without --at the current-balance path is unchanged (no extra API call). Verified live read-only against real data: Mediolanum current 183.23 vs --at 2026-06-10 164.38, boundary probe gives distinct daily balances. PATCH: new optional flag, contract unchanged. 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.py15
1 files changed, 14 insertions, 1 deletions
diff --git a/firefly_cli/commands/account.py b/firefly_cli/commands/account.py
index 9dbfab6..d78f8fc 100644
--- a/firefly_cli/commands/account.py
+++ b/firefly_cli/commands/account.py
@@ -52,9 +52,22 @@ def cmd_get(args, ctx):
output.emit(acc, human=ctx.human)
return 0
-@registry.command("account balance", help="show current balance for one account (name or id)", args=_name_arg)
+def _balance_args(p):
+ p.add_argument("account", help="account name or id")
+ p.add_argument("--at", default=None,
+ help="balance as of this date YYYY-MM-DD (default: current)")
+
+@registry.command("account balance", help="show balance for one account (name or id); --at for a historical date", args=_balance_args)
def cmd_balance(args, ctx):
acc = ctx.resolver.account(args.account)
+ if args.at:
+ # Firefly recomputes current_balance as of ?date= on the account show endpoint.
+ dated = output.unwrap(ctx.client.request(
+ "GET", f"/api/v1/accounts/{acc['id']}", params={"date": args.at}))
+ output.emit({"id": acc["id"], "name": dated.get("name") or acc.get("name"),
+ "date": args.at,
+ "current_balance": dated.get("current_balance")}, human=ctx.human)
+ return 0
output.emit({"id": acc["id"], "name": acc.get("name"),
"current_balance": acc.get("current_balance")}, human=ctx.human)
return 0