Renamed the parameter transaction to txn in the transaction_show(), transaction_edit() and transaction_store() views, to avoid name conflict in the accounting application.
This commit is contained in:
parent
066fd1cb3f
commit
7be26e7447
@ -79,13 +79,13 @@ urlpatterns = [
|
|||||||
views.transaction_edit, name="transactions.create"),
|
views.transaction_edit, name="transactions.create"),
|
||||||
path("transactions/<txn-type:txn_type>/store",
|
path("transactions/<txn-type:txn_type>/store",
|
||||||
views.transaction_store, name="transactions.store"),
|
views.transaction_store, name="transactions.store"),
|
||||||
path("transactions/<txn-type:txn_type>/<txn:transaction>",
|
path("transactions/<txn-type:txn_type>/<txn:txn>",
|
||||||
views.transaction_show, name="transactions.show"),
|
views.transaction_show, name="transactions.show"),
|
||||||
path("transactions/<txn-type:txn_type>/<txn:transaction>/edit",
|
path("transactions/<txn-type:txn_type>/<txn:txn>/edit",
|
||||||
views.transaction_edit, name="transactions.edit"),
|
views.transaction_edit, name="transactions.edit"),
|
||||||
path("transactions/<txn-type:txn_type>/<txn:transaction>/update",
|
path("transactions/<txn-type:txn_type>/<txn:txn>/update",
|
||||||
views.transaction_store, name="transactions.update"),
|
views.transaction_store, name="transactions.update"),
|
||||||
path("transactions/<txn:transaction>/delete",
|
path("transactions/<txn:txn>/delete",
|
||||||
mia_core_views.todo, name="transactions.delete"),
|
mia_core_views.todo, name="transactions.delete"),
|
||||||
path("transactions/sort/<date:date>",
|
path("transactions/sort/<date:date>",
|
||||||
mia_core_views.todo, name="transactions.sort"),
|
mia_core_views.todo, name="transactions.sort"),
|
||||||
|
@ -793,45 +793,45 @@ def search(request):
|
|||||||
|
|
||||||
@require_GET
|
@require_GET
|
||||||
@login_required
|
@login_required
|
||||||
def transaction_show(request, txn_type, transaction):
|
def transaction_show(request, txn_type, txn):
|
||||||
"""The view of an accounting transaction.
|
"""The view of an accounting transaction.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
request (HttpRequest): The request.
|
request (HttpRequest): The request.
|
||||||
txn_type (str): The transaction type.
|
txn_type (str): The transaction type.
|
||||||
transaction (Transaction): The transaction.
|
txn (Transaction): The transaction.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
HttpResponse: The response.
|
HttpResponse: The response.
|
||||||
"""
|
"""
|
||||||
return render(request, F"accounting/transactions/{txn_type}/view.html", {
|
return render(request, F"accounting/transactions/{txn_type}/view.html", {
|
||||||
"item": transaction,
|
"item": txn,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
@require_GET
|
@require_GET
|
||||||
@login_required
|
@login_required
|
||||||
def transaction_edit(request, txn_type, transaction=None):
|
def transaction_edit(request, txn_type, txn=None):
|
||||||
"""The view to edit an accounting transaction.
|
"""The view to edit an accounting transaction.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
request (HttpRequest): The request.
|
request (HttpRequest): The request.
|
||||||
txn_type (str): The transaction type.
|
txn_type (str): The transaction type.
|
||||||
transaction (Transaction): The transaction.
|
txn (Transaction): The transaction.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
HttpResponse: The response.
|
HttpResponse: The response.
|
||||||
"""
|
"""
|
||||||
form = make_transaction_form_from_status(request, txn_type, transaction)
|
form = make_transaction_form_from_status(request, txn_type, txn)
|
||||||
if form is None:
|
if form is None:
|
||||||
exists = transaction is not None
|
exists = txn is not None
|
||||||
if transaction is None:
|
if txn is None:
|
||||||
transaction = Transaction(date=timezone.localdate())
|
txn = Transaction(date=timezone.localdate())
|
||||||
if len(transaction.debit_records) == 0:
|
if len(txn.debit_records) == 0:
|
||||||
transaction.records.append(Record(ord=1, is_credit=False))
|
txn.records.append(Record(ord=1, is_credit=False))
|
||||||
if len(transaction.credit_records) == 0:
|
if len(txn.credit_records) == 0:
|
||||||
transaction.records.append(Record(ord=1, is_credit=True))
|
txn.records.append(Record(ord=1, is_credit=True))
|
||||||
form = make_transaction_form_from_model(transaction, exists)
|
form = make_transaction_form_from_model(txn, exists)
|
||||||
return render(request, F"accounting/transactions/{txn_type}/form.html", {
|
return render(request, F"accounting/transactions/{txn_type}/form.html", {
|
||||||
"item": form,
|
"item": form,
|
||||||
})
|
})
|
||||||
@ -839,13 +839,13 @@ def transaction_edit(request, txn_type, transaction=None):
|
|||||||
|
|
||||||
@require_POST
|
@require_POST
|
||||||
@login_required
|
@login_required
|
||||||
def transaction_store(request, txn_type, transaction=None):
|
def transaction_store(request, txn_type, txn=None):
|
||||||
"""The view to store an accounting transaction.
|
"""The view to store an accounting transaction.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
request (HttpRequest): The request.
|
request (HttpRequest): The request.
|
||||||
txn_type (str): The transaction type.
|
txn_type (str): The transaction type.
|
||||||
transaction (Transaction): The transaction.
|
txn (Transaction): The transaction.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
HttpResponse: The response.
|
HttpResponse: The response.
|
||||||
@ -853,24 +853,24 @@ def transaction_store(request, txn_type, transaction=None):
|
|||||||
post = request.POST.dict()
|
post = request.POST.dict()
|
||||||
strip_form(post)
|
strip_form(post)
|
||||||
sort_form_transaction_records(post)
|
sort_form_transaction_records(post)
|
||||||
form = make_transaction_form_from_post(post, txn_type, transaction)
|
form = make_transaction_form_from_post(post, txn_type, txn)
|
||||||
if not form.is_valid():
|
if not form.is_valid():
|
||||||
if transaction is None:
|
if txn is None:
|
||||||
url = reverse("accounting:transactions.create", args=(txn_type,))
|
url = reverse("accounting:transactions.create", args=(txn_type,))
|
||||||
else:
|
else:
|
||||||
url = reverse(
|
url = reverse(
|
||||||
"accounting:transactions.edit", args=(txn_type, transaction))
|
"accounting:transactions.edit", args=(txn_type, txn))
|
||||||
return error_redirect(
|
return error_redirect(
|
||||||
request,
|
request,
|
||||||
str(UrlBuilder(url).set("r", request.GET.get("r"))),
|
str(UrlBuilder(url).set("r", request.GET.get("r"))),
|
||||||
post)
|
post)
|
||||||
if transaction is None:
|
if txn is None:
|
||||||
transaction = Transaction()
|
txn = Transaction()
|
||||||
fill_transaction_from_post(transaction, post)
|
fill_transaction_from_post(txn, post)
|
||||||
# TODO: Stores the data
|
# TODO: Stores the data
|
||||||
return success_redirect(
|
return success_redirect(
|
||||||
request,
|
request,
|
||||||
str(UrlBuilder(reverse("accounting:transactions.show",
|
str(UrlBuilder(reverse("accounting:transactions.show",
|
||||||
args=(txn_type, transaction)))
|
args=(txn_type, txn)))
|
||||||
.add("r", request.GET.get("r"))),
|
.add("r", request.GET.get("r"))),
|
||||||
gettext_noop("This transaction was saved successfully."))
|
gettext_noop("This transaction was saved successfully."))
|
||||||
|
Loading…
Reference in New Issue
Block a user