From 1b9ea452d955513a6fe23ed6c626878e40ab981d Mon Sep 17 00:00:00 2001 From: Herculino Trotta Date: Thu, 5 Nov 2026 00:14:41 -0300 Subject: [PATCH] feat(transactions): prefill add and transfer forms from query parameters transaction_add accepts account and entities; transactions_transfer accepts from_account and to_account. Applied only when present. --- app/apps/transactions/views/transactions.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/apps/transactions/views/transactions.py b/app/apps/transactions/views/transactions.py index a18c17bf..9ceab0a5 100644 --- a/app/apps/transactions/views/transactions.py +++ b/app/apps/transactions/views/transactions.py @@ -119,6 +119,15 @@ def transaction_attachment_delete(request, attachment_id): return response +def _prefill(request, *fields, entities=False): + """Form initial values passed as query parameters; only the named ones, and + only when present, so they never override other defaults.""" + initial = {name: request.GET[name] for name in fields if request.GET.get(name)} + if entities and request.GET.getlist("entities"): + initial["entities"] = request.GET.getlist("entities") # entity names + return initial + + @only_htmx @login_required @require_http_methods(["GET", "POST"]) @@ -204,6 +213,8 @@ def transaction_add(request): initial={ "date": expected_date, "type": transaction_type, + # Optional prefill, e.g. a dividend from the investments page + **_prefill(request, "account", entities=True), }, ) @@ -541,6 +552,8 @@ def transactions_transfer(request): initial={ "reference_date": expected_date, "date": expected_date, + # Optional prefill, e.g. buy/sell from the investments page + **_prefill(request, "from_account", "to_account"), }, )