aboutsummaryrefslogtreecommitdiffstats
path: root/firefly_cli/commands/budget.py
diff options
context:
space:
mode:
Diffstat (limited to 'firefly_cli/commands/budget.py')
-rw-r--r--firefly_cli/commands/budget.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/firefly_cli/commands/budget.py b/firefly_cli/commands/budget.py
index 86317fa..8e35a16 100644
--- a/firefly_cli/commands/budget.py
+++ b/firefly_cli/commands/budget.py
@@ -99,6 +99,38 @@ def _set_active(ctx, ref, active):
output.emit(output.unwrap(resp), human=ctx.human)
return 0
+def _update_args(p):
+ _ref_arg(p)
+ p.add_argument("--name", default=None, help="new budget name")
+ p.add_argument("--currency", default=None, help="auto-budget currency code, e.g. EUR")
+ p.add_argument("--auto-budget-amount", dest="auto_budget_amount", default=None,
+ help="recurring auto-budget amount")
+ p.add_argument("--auto-budget-period", dest="auto_budget_period", default=None,
+ help="daily|weekly|monthly|quarterly|half_year|yearly")
+ p.add_argument("--auto-budget-type", dest="auto_budget_type", default=None,
+ help="reset|rollover|adjusted|none")
+
+@registry.command("budget update", help="rename a budget and/or edit its auto-budget fields (name or id)", args=_update_args)
+def cmd_update(args, ctx):
+ b = ctx.resolver.budget(args.ref)
+ body = {}
+ if args.name is not None:
+ body["name"] = args.name
+ if args.auto_budget_amount is not None:
+ body["auto_budget_amount"] = str(args.auto_budget_amount)
+ if args.auto_budget_period is not None:
+ body["auto_budget_period"] = args.auto_budget_period
+ if args.auto_budget_type is not None:
+ body["auto_budget_type"] = args.auto_budget_type
+ if args.currency:
+ body["currency_code"] = args.currency
+ if not body:
+ raise FireflyError("budget update: nothing to change; pass at least one field")
+ resp = ctx.client.request("PUT", f"/api/v1/budgets/{b['id']}", body=body)
+ output.emit(output.unwrap(resp), human=ctx.human)
+ return 0
+
+
@registry.command("budget enable", help="mark a budget active", args=_ref_arg)
def cmd_enable(args, ctx):
return _set_active(ctx, args.ref, True)