Add links to create snapshot in account, transaction in snapshot

This commit is contained in:
Edgar P. Burkhart 2022-12-31 11:59:33 +01:00
parent 6b54cc7546
commit 65a35b31f0
Signed by: edpibu
GPG Key ID: 9833D3C5A25BD227
5 changed files with 51 additions and 12 deletions

View File

@ -24,8 +24,8 @@
padding: 1em;
white-space: nowrap;
}
.table > div.g> * {background: var(--bg-01)}
.table > div.w> * {background: var(--bg)}
.table > div:nth-child(odd) > * {background: var(--bg-01)}
.table > div:nth-child(even) > * {background: var(--bg)}
.table > div.header > * {
background: var(--theme);

View File

@ -10,8 +10,13 @@
<strong class="diff center">{% translate "Transactions" %}</strong>
<strong class="diff center">{% translate "Valid" %}</strong>
</div>
{% if new_snapshot_url %}
<div class="full-line">
<a href="{{ new_snapshot_url }}">{% translate "New statement" %}</a>
</div>
{% endif %}
{% for snap in snapshots %}
<div class="snapshot {% cycle 'w' 'g' %}">
<div class="snapshot">
<span class="attach center">
{% if snap.file %}
<a href="{{ snap.file.url }}">
@ -20,11 +25,11 @@
{% endif %}
</span>
<span class="date num center">
<a href="{% url 'snapshot' snap.id %}">{{ snap.date|date:"Y-m-d" }}</a>
<a href="{% url 'snapshot' pk=snap.id %}">{{ snap.date|date:"Y-m-d" }}</a>
</span>
<span class="account text center">
<i class="fa fa-{{ snap.account.icon }}"></i>
<a href="{% url 'account' snap.account.id %}">{{ snap.account }}</a>
<a href="{% url 'account' pk=snap.account.id %}">{{ snap.account }}</a>
</span>
<span class="value num right">{{ snap.value|value }}</span>
<span class="diff num right">{{ snap.diff|pmvalue }}</span>
@ -41,7 +46,7 @@
</div>
{% endfor %}
{% if snapshots_url %}
<div class="full-line {% cycle "w" "g" %}">
<div class="full-line">
<a href="{{ snapshots_url }}">{% translate "View all statements" %}</a>
</div>
{% endif %}

View File

@ -11,8 +11,13 @@
<strong class="account center">{% translate "Account" %}</strong>
<strong class="description">{% translate "Description" %}</strong>
</div>
{% if new_transaction_url %}
<div class="full-line">
<a href="{{ new_transaction_url }}">{% translate "New transaction" %}</a>
</div>
{% endif %}
{% for trans in transactions %}
<div class="transaction {% cycle 'w' 'g' %}">
<div class="transaction">
<span class="attach center">
{% for invoice in trans.invoices %}
{% spaceless %}
@ -23,13 +28,13 @@
{% endfor %}
</span>
<span class="date num center">{{ trans.date|date:"Y-m-d" }}</span>
<span class="name text"><a href="{% url 'transaction' trans.id %}">{{ trans.name }}</a></span>
<span class="name text"><a href="{% url 'transaction' pk=trans.id %}">{{ trans.name }}</a></span>
<span class="value num right">{{ trans.value|pmvalue }}</span>
<span class="trader text center">{{ trans.trader|default_if_none:"" }}</span>
<span class="category text center">
{% if trans.category %}
<i class="fa fa-{{ trans.category.icon }}"></i>
<a href="{% url 'category' trans.category.id %}">{{ trans.category }}</a>
<a href="{% url 'category' pk=trans.category.id %}">{{ trans.category }}</a>
{% else %}
{% endif %}
@ -37,7 +42,7 @@
<span class="account text center">
{% if trans.account %}
<i class="fa fa-{{ trans.account.icon }}"></i>
<a href="{% url 'account' trans.account.id %}">{{ trans.account }}</a>
<a href="{% url 'account' pk=trans.account.id %}">{{ trans.account }}</a>
{% else %}
{% endif %}
@ -46,7 +51,7 @@
</div>
{% endfor %}
{% if transactions_url %}
<div class="full-line {% cycle "w" "g" %}">
<div class="full-line">
<a href="{{ transactions_url }}">{% translate "View all transactions" %}</a>
</div>
{% endif %}

View File

@ -28,6 +28,11 @@ urlpatterns = [
views.AccountSListView.as_view(),
name="account_snapshots",
),
path(
"account/<account>/snapshot",
views.SnapshotCreateView.as_view(),
name="snapshot",
),
path("transaction/<pk>", views.TransactionUpdateView.as_view(), name="transaction"),
path(
"transaction/<transaction_pk>/invoice/<pk>",
@ -46,6 +51,11 @@ urlpatterns = [
views.SnapshotTListView.as_view(),
name="snapshot_transactions",
),
path(
"snapshot/<snapshot>/transaction",
views.TransactionCreateView.as_view(),
name="transaction",
),
path(
"account/<pk>/delete",
views.AccountDeleteView.as_view(),

View File

@ -53,7 +53,6 @@ class UserFormMixin:
def get_form_kwargs(self):
return super().get_form_kwargs() | {
"user": self.request.user,
"initial": self.request.GET,
}
@ -90,6 +89,13 @@ class TransactionCreateView(NummiCreateView):
model = Transaction
form_class = TransactionForm
def get_form_kwargs(self):
return super().get_form_kwargs() | {
"initial": {
"snapshot": self.kwargs.get("snapshot"),
},
}
class InvoiceCreateView(NummiCreateView):
model = Invoice
@ -115,6 +121,13 @@ class SnapshotCreateView(NummiCreateView):
model = Snapshot
form_class = SnapshotForm
def get_form_kwargs(self):
return super().get_form_kwargs() | {
"initial": {
"account": self.kwargs.get("account"),
},
}
class AccountUpdateView(NummiUpdateView):
model = Account
@ -128,6 +141,9 @@ class AccountUpdateView(NummiUpdateView):
"transactions_url": reverse_lazy(
"account_transactions", args=(account.pk,)
),
"new_snapshot_url": reverse_lazy(
"snapshot", kwargs={"account": account.pk}
),
"snapshots": account.snapshot_set.all()[:8],
"snapshots_url": reverse_lazy("account_snapshots", args=(account.pk,)),
}
@ -180,6 +196,9 @@ class SnapshotUpdateView(NummiUpdateView):
data = super().get_context_data(**kwargs)
snapshot = data["form"].instance
return data | {
"new_transaction_url": reverse_lazy(
"transaction", kwargs={"snapshot": snapshot.pk}
),
"transactions": snapshot.transaction_set.all()[:8],
"transactions_url": reverse_lazy(
"snapshot_transactions", args=(snapshot.pk,)