Implemented frontend for transactions and invoices

This commit is contained in:
Edgar P. Burkhart 2023-04-22 12:44:34 +02:00
parent a98b073eea
commit ee25223e73
Signed by: edpibu
GPG key ID: 9833D3C5A25BD227
8 changed files with 46 additions and 71 deletions

View file

@ -1,27 +0,0 @@
{% extends "main/base.html" %}
{% load static %}
{% load main_extras %}
{% load i18n %}
{% block link %}
{{ block.super }}
<link rel="stylesheet"
href="{% static 'main/css/table.css' %}"
type="text/css" />
<link rel="stylesheet"
href="{% static 'main/css/plot.css' %}"
type="text/css" />
{% endblock %}
{% block body %}
<h2>{% translate "Transactions" %} {{ month|date:"F Y"|capfirst }}</h2>
{% if account %}
<p>
<a href="{% url "account" account.pk %}">{{ account.icon|remix }}{{ account }}</a>
</p>
{% endif %}
{% if category %}
<p>
<a href="{% url "category" category.pk %}">{{ category.icon|remix }}{{ category }}</a>
</p>
{% endif %}
{% include "main/table/transaction.html" %}
{% endblock %}

View file

@ -67,7 +67,7 @@ class Transaction(UserModel):
return reverse("transaction", kwargs={"pk": self.pk}) return reverse("transaction", kwargs={"pk": self.pk})
def get_delete_url(self): def get_delete_url(self):
return reverse("del_transaction", kwargs={"pk": self.pk}) return reverse("del_transaction", args=(self.pk,))
@property @property
def invoices(self): def invoices(self):
@ -113,14 +113,10 @@ class Invoice(UserModel):
super().delete(*args, **kwargs) super().delete(*args, **kwargs)
def get_absolute_url(self): def get_absolute_url(self):
return reverse( return reverse("invoice", args=(self.transaction.pk, self.pk))
"invoice", kwargs={"transaction_pk": self.transaction.pk, "pk": self.pk}
)
def get_delete_url(self): def get_delete_url(self):
return reverse( return reverse("del_invoice", args=(self.transaction.pk, self.pk))
"del_invoice", kwargs={"transaction_pk": self.transaction.pk, "pk": self.pk}
)
class Meta: class Meta:
verbose_name = _("Invoice") verbose_name = _("Invoice")

View file

@ -0,0 +1,2 @@
{% extends "transaction/transaction_list.html" %}
{% block h2 %}{{ month|date:"F Y"|capfirst }}{% endblock %}

View file

@ -21,7 +21,11 @@
type="text/css" /> type="text/css" />
{% endblock %} {% endblock %}
{% block body %} {% block body %}
<h2>{% translate "Transactions" %}</h2> <h2>
{% block h2 %}
{% translate "Transactions" %}
{% endblock %}
</h2>
{% if account %} {% if account %}
<p> <p>
<a href="{{ account.get_absolute_url }}">{{ account.icon|remix }}{{ account }}</a> <a href="{{ account.get_absolute_url }}">{{ account.icon|remix }}{{ account }}</a>
@ -33,7 +37,9 @@
</p> </p>
{% endif %} {% endif %}
{% if search %} {% if search %}
<a href="{% url "search" %}">{% translate "Search" %}</a> <p>
<a href="{% url "search" %}">{% translate "Search" %}</a>
</p>
{% endif %} {% endif %}
{% if transactions %} {% if transactions %}
{% include "main/list/pagination.html" %} {% include "main/list/pagination.html" %}

View file

@ -3,32 +3,32 @@ from django.urls import path
from . import views from . import views
urlpatterns = [ urlpatterns = [
path("transactions", views.TransactionListView.as_view(), name="transactions"), path("list", views.TransactionListView.as_view(), name="transactions"),
path("transaction", views.TransactionCreateView.as_view(), name="new_transaction"),
path(
"transaction/<transaction_pk>/invoice",
views.InvoiceCreateView.as_view(),
name="new_invoice",
),
path("transaction/<pk>", views.TransactionUpdateView.as_view(), name="transaction"),
path(
"transaction/<transaction_pk>/invoice/<pk>",
views.InvoiceUpdateView.as_view(),
name="invoice",
),
path(
"transaction/<pk>/delete",
views.TransactionDeleteView.as_view(),
name="del_transaction",
),
path(
"transaction/<transaction_pk>/invoice/<pk>/delete",
views.InvoiceDeleteView.as_view(),
name="del_invoice",
),
path( path(
"history/<int:year>/<int:month>", "history/<int:year>/<int:month>",
views.TransactionMonthView.as_view(), views.TransactionMonthView.as_view(),
name="transaction_month", name="transaction_month",
), ),
path("new", views.TransactionCreateView.as_view(), name="new_transaction"),
path("<transaction>", views.TransactionUpdateView.as_view(), name="transaction"),
path(
"<transaction>/delete",
views.TransactionDeleteView.as_view(),
name="del_transaction",
),
path(
"<transaction>/invoice/new",
views.InvoiceCreateView.as_view(),
name="new_invoice",
),
path(
"<transaction>/invoice/<invoice>",
views.InvoiceUpdateView.as_view(),
name="invoice",
),
path(
"<transaction>/invoice/<invoice>/delete",
views.InvoiceDeleteView.as_view(),
name="del_invoice",
),
] ]

View file

@ -19,7 +19,6 @@ from .models import Invoice, Transaction
class TransactionCreateView(NummiCreateView): class TransactionCreateView(NummiCreateView):
model = Transaction model = Transaction
form_class = TransactionForm form_class = TransactionForm
template_name = "main/form/transaction.html"
def get_initial(self): def get_initial(self):
_queryset = Statement.objects.filter(user=self.request.user) _queryset = Statement.objects.filter(user=self.request.user)
@ -43,32 +42,31 @@ class TransactionCreateView(NummiCreateView):
class InvoiceCreateView(NummiCreateView): class InvoiceCreateView(NummiCreateView):
model = Invoice model = Invoice
form_class = InvoiceForm form_class = InvoiceForm
template_name = "main/form/invoice.html"
def form_valid(self, form): def form_valid(self, form):
form.instance.transaction = get_object_or_404( form.instance.transaction = get_object_or_404(
Transaction.objects.filter(user=self.request.user), Transaction.objects.filter(user=self.request.user),
pk=self.kwargs["transaction_pk"], pk=self.kwargs["transaction"],
) )
return super().form_valid(form) return super().form_valid(form)
def get_success_url(self): def get_success_url(self):
return reverse_lazy("transaction", kwargs={"pk": self.object.transaction.pk}) return reverse_lazy("transaction", args=(self.object.transaction.pk,))
class TransactionUpdateView(NummiUpdateView): class TransactionUpdateView(NummiUpdateView):
model = Transaction model = Transaction
form_class = TransactionForm form_class = TransactionForm
template_name = "main/form/transaction.html" pk_url_kwarg = "transaction"
class InvoiceUpdateView(NummiUpdateView): class InvoiceUpdateView(NummiUpdateView):
model = Invoice model = Invoice
form_class = InvoiceForm form_class = InvoiceForm
template_name = "main/form/invoice.html" pk_url_kwarg = "invoice"
def get_success_url(self): def get_success_url(self):
return reverse_lazy("transaction", kwargs={"pk": self.object.transaction.pk}) return reverse_lazy("transaction", args=(self.object.transaction.pk,))
def get_queryset(self): def get_queryset(self):
return ( return (
@ -76,7 +74,7 @@ class InvoiceUpdateView(NummiUpdateView):
.get_queryset() .get_queryset()
.filter( .filter(
transaction=get_object_or_404( transaction=get_object_or_404(
Transaction, pk=self.kwargs["transaction_pk"] Transaction, pk=self.kwargs["transaction"]
) )
) )
) )
@ -84,13 +82,15 @@ class InvoiceUpdateView(NummiUpdateView):
class TransactionDeleteView(NummiDeleteView): class TransactionDeleteView(NummiDeleteView):
model = Transaction model = Transaction
pk_url_kwarg = "transaction"
class InvoiceDeleteView(NummiDeleteView): class InvoiceDeleteView(NummiDeleteView):
model = Invoice model = Invoice
pk_url_kwarg = "invoice"
def get_success_url(self): def get_success_url(self):
return reverse_lazy("transaction", kwargs={"pk": self.object.transaction.pk}) return reverse_lazy("transaction", args=(self.object.transaction.pk,))
def get_queryset(self): def get_queryset(self):
return ( return (
@ -98,7 +98,7 @@ class InvoiceDeleteView(NummiDeleteView):
.get_queryset() .get_queryset()
.filter( .filter(
transaction=get_object_or_404( transaction=get_object_or_404(
Transaction, pk=self.kwargs["transaction_pk"] Transaction, pk=self.kwargs["transaction"]
) )
) )
) )
@ -106,12 +106,10 @@ class InvoiceDeleteView(NummiDeleteView):
class TransactionListView(NummiListView): class TransactionListView(NummiListView):
model = Transaction model = Transaction
template_name = "main/list/transaction.html"
context_object_name = "transactions" context_object_name = "transactions"
class TransactionMonthView(UserMixin, MonthArchiveView): class TransactionMonthView(UserMixin, MonthArchiveView):
template_name = "main/month/transaction.html"
model = Transaction model = Transaction
date_field = "date" date_field = "date"
context_object_name = "transactions" context_object_name = "transactions"