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",
"statement",
"transaction",
"search",
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",

View file

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

View file

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

View file

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

View file

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

View file

@ -67,7 +67,7 @@ class Transaction(UserModel):
return reverse("transaction", kwargs={"pk": self.pk})
def get_delete_url(self):
return reverse("del_transaction", kwargs={"pk": self.pk})
return reverse("del_transaction", args=(self.pk,))
@property
def invoices(self):
@ -113,14 +113,10 @@ class Invoice(UserModel):
super().delete(*args, **kwargs)
def get_absolute_url(self):
return reverse(
"invoice", kwargs={"transaction_pk": self.transaction.pk, "pk": self.pk}
)
return reverse("invoice", args=(self.transaction.pk, self.pk))
def get_delete_url(self):
return reverse(
"del_invoice", kwargs={"transaction_pk": self.transaction.pk, "pk": self.pk}
)
return reverse("del_invoice", args=(self.transaction.pk, self.pk))
class Meta:
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" />
{% endblock %}
{% block body %}
<h2>{% translate "Transactions" %}</h2>
<h2>
{% block h2 %}
{% translate "Transactions" %}
{% endblock %}
</h2>
{% if account %}
<p>
<a href="{{ account.get_absolute_url }}">{{ account.icon|remix }}{{ account }}</a>
@ -33,7 +37,9 @@
</p>
{% endif %}
{% if search %}
<p>
<a href="{% url "search" %}">{% translate "Search" %}</a>
</p>
{% endif %}
{% if transactions %}
{% include "main/list/pagination.html" %}

View file

@ -3,32 +3,32 @@ from django.urls import path
from . import views
urlpatterns = [
path("transactions", 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("list", views.TransactionListView.as_view(), name="transactions"),
path(
"history/<int:year>/<int:month>",
views.TransactionMonthView.as_view(),
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):
model = Transaction
form_class = TransactionForm
template_name = "main/form/transaction.html"
def get_initial(self):
_queryset = Statement.objects.filter(user=self.request.user)
@ -43,32 +42,31 @@ class TransactionCreateView(NummiCreateView):
class InvoiceCreateView(NummiCreateView):
model = Invoice
form_class = InvoiceForm
template_name = "main/form/invoice.html"
def form_valid(self, form):
form.instance.transaction = get_object_or_404(
Transaction.objects.filter(user=self.request.user),
pk=self.kwargs["transaction_pk"],
pk=self.kwargs["transaction"],
)
return super().form_valid(form)
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):
model = Transaction
form_class = TransactionForm
template_name = "main/form/transaction.html"
pk_url_kwarg = "transaction"
class InvoiceUpdateView(NummiUpdateView):
model = Invoice
form_class = InvoiceForm
template_name = "main/form/invoice.html"
pk_url_kwarg = "invoice"
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):
return (
@ -76,7 +74,7 @@ class InvoiceUpdateView(NummiUpdateView):
.get_queryset()
.filter(
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):
model = Transaction
pk_url_kwarg = "transaction"
class InvoiceDeleteView(NummiDeleteView):
model = Invoice
pk_url_kwarg = "invoice"
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):
return (
@ -98,7 +98,7 @@ class InvoiceDeleteView(NummiDeleteView):
.get_queryset()
.filter(
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):
model = Transaction
template_name = "main/list/transaction.html"
context_object_name = "transactions"
class TransactionMonthView(UserMixin, MonthArchiveView):
template_name = "main/month/transaction.html"
model = Transaction
date_field = "date"
context_object_name = "transactions"