Add transaction creation
This commit is contained in:
parent
6ef5a441e1
commit
eddfa4708f
2 changed files with 13 additions and 5 deletions
|
@ -4,6 +4,7 @@ from . import views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("", views.index, name="index"),
|
path("", views.index, name="index"),
|
||||||
|
path("transaction", views.transaction, name="transaction"),
|
||||||
path("transaction/<uuid>", views.transaction, name="transaction"),
|
path("transaction/<uuid>", views.transaction, name="transaction"),
|
||||||
path(
|
path(
|
||||||
"transaction/<uuid>/update", views.update_transaction, name="update_transaction"
|
"transaction/<uuid>/update", views.update_transaction, name="update_transaction"
|
||||||
|
|
|
@ -6,16 +6,20 @@ from .models import Transaction, TransactionForm, Invoice, InvoiceForm
|
||||||
|
|
||||||
|
|
||||||
def index(request):
|
def index(request):
|
||||||
_transactions = Transaction.objects.order_by("date")[:5]
|
_transactions = Transaction.objects.order_by("-date")[:5]
|
||||||
context = {
|
context = {
|
||||||
"transactions": _transactions,
|
"transactions": _transactions,
|
||||||
}
|
}
|
||||||
return render(request, "main/index.html", context)
|
return render(request, "main/index.html", context)
|
||||||
|
|
||||||
|
|
||||||
def transaction(request, uuid):
|
def transaction(request, uuid=None):
|
||||||
_transaction = get_object_or_404(Transaction, id=uuid)
|
if uuid is None:
|
||||||
_invoices = Invoice.objects.filter(transaction=_transaction)
|
_transaction = Transaction()
|
||||||
|
_invoices = []
|
||||||
|
else:
|
||||||
|
_transaction = get_object_or_404(Transaction, id=uuid)
|
||||||
|
_invoices = Invoice.objects.filter(transaction=_transaction)
|
||||||
return render(
|
return render(
|
||||||
request,
|
request,
|
||||||
"main/transaction.html",
|
"main/transaction.html",
|
||||||
|
@ -29,7 +33,10 @@ def transaction(request, uuid):
|
||||||
|
|
||||||
|
|
||||||
def update_transaction(request, uuid):
|
def update_transaction(request, uuid):
|
||||||
_transaction = get_object_or_404(Transaction, id=uuid)
|
try:
|
||||||
|
_transaction = Transaction.objects.get(id=uuid)
|
||||||
|
except Transaction.DoesNotExist:
|
||||||
|
_transaction = Transaction(id=uuid)
|
||||||
_form = TransactionForm(request.POST, instance=_transaction)
|
_form = TransactionForm(request.POST, instance=_transaction)
|
||||||
_form.save()
|
_form.save()
|
||||||
return redirect(transaction, uuid=uuid)
|
return redirect(transaction, uuid=uuid)
|
||||||
|
|
Loading…
Reference in a new issue