diff options
Diffstat (limited to 'firefly_cli/commands')
| -rw-r--r-- | firefly_cli/commands/budget.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/firefly_cli/commands/budget.py b/firefly_cli/commands/budget.py index 3994958..733d092 100644 --- a/firefly_cli/commands/budget.py +++ b/firefly_cli/commands/budget.py @@ -105,3 +105,31 @@ def cmd_enable(args, ctx): @registry.command("budget disable", help="mark a budget inactive", args=_ref_arg) def cmd_disable(args, ctx): return _set_active(ctx, args.ref, False) + + +@registry.command("budget limit list", help="list a budget's limits (name or id)", args=_ref_arg) +def cmd_limit_list(args, ctx): + b = ctx.resolver.budget(args.ref) + resp = ctx.client.request("GET", f"/api/v1/budgets/{b['id']}/limits") + output.emit(output.unwrap(resp), human=ctx.human) + return 0 + +def _limit_set_args(p): + _ref_arg(p) + p.add_argument("--amount", required=True, help="limit amount (positive)") + p.add_argument("--start", default=None, help="YYYY-MM-DD (default: 1st of this month)") + p.add_argument("--end", default=None, help="YYYY-MM-DD (default: last of this month)") + p.add_argument("--currency", default=None, help="currency code, e.g. EUR") + +@registry.command("budget limit set", help="set (create) a spending limit for a budget over a period", args=_limit_set_args) +def cmd_limit_set(args, ctx): + b = ctx.resolver.budget(args.ref) + first, last = _current_month() + body = {"amount": str(args.amount), + "start": args.start or first, + "end": args.end or last} + if args.currency: + body["currency_code"] = args.currency + resp = ctx.client.request("POST", f"/api/v1/budgets/{b['id']}/limits", body=body) + output.emit(output.unwrap(resp), human=ctx.human) + return 0 |
