From b078c5980facc0ebe4acd1f251f6ae3dad561292 Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Wed, 1 Jul 2026 10:29:04 +0200 Subject: 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 --- tests/unit/test_commands_account.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'tests/unit') diff --git a/tests/unit/test_commands_account.py b/tests/unit/test_commands_account.py index 2c07780..4a01292 100644 --- a/tests/unit/test_commands_account.py +++ b/tests/unit/test_commands_account.py @@ -22,11 +22,25 @@ class TestAccountCmd(unittest.TestCase): ctx, client, resolver = make_ctx() resolver.account.return_value = {"id": "3", "name": "Checking", "current_balance": "100.00"} - args = MagicMock(account="Checking") + args = MagicMock(account="Checking", at=None) rc = acct.cmd_balance(args, ctx) resolver.account.assert_called_once_with("Checking") + client.request.assert_not_called() # current balance from resolver, no extra call self.assertEqual(rc, 0) + def test_balance_at_date_fetches_dated_account(self): + ctx, client, resolver = make_ctx() + resolver.account.return_value = {"id": "3", "name": "Checking", + "current_balance": "100.00"} + client.request.return_value = {"data": {"id": "3", "attributes": { + "name": "Checking", "current_balance": "42.00"}}} + args = MagicMock(account="Checking", at="2026-05-31") + rc = acct.cmd_balance(args, ctx) + self.assertEqual(rc, 0) + method, path = client.request.call_args[0][:2] + self.assertEqual((method, path), ("GET", "/api/v1/accounts/3")) + self.assertEqual(client.request.call_args[1]["params"], {"date": "2026-05-31"}) + class TestAccountCreate(unittest.TestCase): def _args(self, **kw): base = dict(name=None, type=None, opening_balance=None, currency=None) -- cgit v1.2.3