Compare commits

...

3 commits

16 changed files with 64 additions and 88 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

@ -50,6 +50,7 @@ INSTALLED_APPS = [
"category", "category",
"statement", "statement",
"transaction", "transaction",
"search",
"django.contrib.admin", "django.contrib.admin",
"django.contrib.auth", "django.contrib.auth",
"django.contrib.contenttypes", "django.contrib.contenttypes",

View file

@ -14,7 +14,7 @@ from .forms import SearchForm
class SearchFormView(LoginRequiredMixin, FormView): class SearchFormView(LoginRequiredMixin, FormView):
template_name = "main/search.html" template_name = "search/search.html"
form_class = SearchForm form_class = SearchForm
def form_valid(self, form): def form_valid(self, form):

View file

@ -79,10 +79,10 @@ class Statement(AccountModel):
super().delete(*args, **kwargs) super().delete(*args, **kwargs)
def get_absolute_url(self): def get_absolute_url(self):
return reverse("statement", kwargs={"pk": self.pk}) return reverse("statement", args=(self.pk,))
def get_delete_url(self): def get_delete_url(self):
return reverse("del_statement", kwargs={"pk": self.pk}) return reverse("del_statement", args=(self.pk,))
class Meta: class Meta:
ordering = ["-date", "account"] ordering = ["-date", "account"]

View file

@ -4,21 +4,21 @@ from transaction.views import TransactionCreateView
from . import views from . import views
urlpatterns = [ urlpatterns = [
path("statements", views.StatementListView.as_view(), name="statements"), path("list", views.StatementListView.as_view(), name="statements"),
path("statement", views.StatementCreateView.as_view(), name="new_statement"), path("new", views.StatementCreateView.as_view(), name="new_statement"),
path("statement/<pk>", views.StatementUpdateView.as_view(), name="statement"), path("<statement>", views.StatementUpdateView.as_view(), name="statement"),
path( path(
"statement/<pk>/transactions", "<statement>/transaction/list",
views.StatementTListView.as_view(), views.StatementTListView.as_view(),
name="statement_transactions", name="statement_transactions",
), ),
path( path(
"statement/<statement>/transaction", "<statement>/transaction/new",
TransactionCreateView.as_view(), TransactionCreateView.as_view(),
name="new_transaction", name="new_transaction",
), ),
path( path(
"statement/<pk>/delete", "<statement>/delete",
views.StatementDeleteView.as_view(), views.StatementDeleteView.as_view(),
name="del_statement", name="del_statement",
), ),

View file

@ -12,7 +12,6 @@ from .models import Statement
class StatementCreateView(NummiCreateView): class StatementCreateView(NummiCreateView):
model = Statement model = Statement
form_class = StatementForm form_class = StatementForm
template_name = "main/form/statement.html"
def get_initial(self): def get_initial(self):
_queryset = Account.objects.filter(user=self.request.user) _queryset = Account.objects.filter(user=self.request.user)
@ -36,7 +35,7 @@ class StatementCreateView(NummiCreateView):
class StatementUpdateView(NummiUpdateView): class StatementUpdateView(NummiUpdateView):
model = Statement model = Statement
form_class = StatementForm form_class = StatementForm
template_name = "main/form/statement.html" pk_url_kwarg = "statement"
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
data = super().get_context_data(**kwargs) data = super().get_context_data(**kwargs)
@ -74,23 +73,24 @@ class StatementUpdateView(NummiUpdateView):
class StatementDeleteView(NummiDeleteView): class StatementDeleteView(NummiDeleteView):
model = Statement model = Statement
pk_url_kwarg = "statement"
class StatementListView(NummiListView): class StatementListView(NummiListView):
model = Statement model = Statement
template_name = "main/list/statement.html"
context_object_name = "statements" context_object_name = "statements"
class StatementMixin: class StatementMixin:
def get_queryset(self): def get_queryset(self):
return super().get_queryset().filter(statement=self.kwargs.get("pk")) self.statement = get_object_or_404(
Statement.objects.filter(user=self.request.user),
pk=self.kwargs.get("statement"),
)
return super().get_queryset().filter(statement=self.statement)
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
return super().get_context_data(**kwargs) | { return super().get_context_data(**kwargs) | {"statement": self.statement}
"object": Statement.objects.get(pk=self.kwargs.get("pk")),
"statement": True,
}
class StatementTListView(StatementMixin, TransactionListView): class StatementTListView(StatementMixin, TransactionListView):

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 %}
<p>
<a href="{% url "search" %}">{% translate "Search" %}</a> <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"