aboutsummaryrefslogtreecommitdiffstats
path: root/firefly_cli/output.py
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-07-01 12:13:42 +0200
committerDanilo M. <danix@danix.xyz>2026-07-01 12:13:42 +0200
commit941ccb2cb34944e1321b3dc23731bfa93018d74f (patch)
tree72f5ccb1c9c0d90c320aa17dda4ddb4b8a444f40 /firefly_cli/output.py
parent60e15f9ced98c270a48d58ac000738afb78c2d7e (diff)
downloadfirefly-cli-941ccb2cb34944e1321b3dc23731bfa93018d74f.tar.gz
firefly-cli-941ccb2cb34944e1321b3dc23731bfa93018d74f.zip
feat: tx list --flat, account create --if-not-exists, --since/--until doc (v0.3.6)v0.3.6
Three smaller ISSUES.md items, one PATCH (two optional flags + a doc fix; no existing caller or JSON shape changes). - tx list --flat: emit one top-level object per split (journal id repeated), dropping the transactions[] nesting so single-split journals script cleanly. JSON-only; --human already explodes splits into a table. - account create --if-not-exists: resolve the name first; on a clash return the existing account with "existed": true (exit 0) instead of surfacing Firefly's 422, so import scripts are idempotent. Detects via resolver, not by parsing the error string. - SKILL.md documents that --since/--until filter on the transaction date (the value date); Firefly journals have a single date field, no separate book date (verified against firefly-iii TimeCollection setRange). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Diffstat (limited to 'firefly_cli/output.py')
-rw-r--r--firefly_cli/output.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/firefly_cli/output.py b/firefly_cli/output.py
index 166e1bf..6c6a61c 100644
--- a/firefly_cli/output.py
+++ b/firefly_cli/output.py
@@ -62,6 +62,27 @@ def _tx_rows(rows):
def _is_tx(rows):
return bool(rows) and isinstance(rows[0], dict) and "transactions" in rows[0]
+def flatten_tx(rows):
+ """Explode unwrapped tx journals into one flat object per split.
+
+ Each journal is {id, transactions: [split, ...], ...}. We emit one object
+ per split: the split's raw Firefly fields (source_name, amount, etc.) with
+ the journal id merged in and the `transactions` list dropped. Single-split
+ journals (the common case) become one clean object. Rows without a
+ `transactions` list pass through unchanged.
+ """
+ out = []
+ for r in rows:
+ splits = r.get("transactions")
+ if not isinstance(splits, list):
+ out.append(r)
+ continue
+ for s in splits:
+ flat = dict(s)
+ flat["id"] = r.get("id")
+ out.append(flat)
+ return out
+
# Per-resource column whitelists for --human. Firefly returns ~50 fields per
# row; only a handful are worth a table. A row is matched by a signature key.
# (signature, columns) -- first match wins; unmatched rows use a generic table.