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