Separate detail and edit view for category, update statement page
This commit is contained in:
parent
218a6aca6f
commit
9d50dc7154
15 changed files with 120 additions and 96 deletions
|
@ -7,7 +7,7 @@ msgid ""
|
|||
msgstr ""
|
||||
"Project-Id-Version: \n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2024-01-04 16:04+0100\n"
|
||||
"POT-Creation-Date: 2024-01-04 16:18+0100\n"
|
||||
"PO-Revision-Date: 2023-04-22 15:17+0200\n"
|
||||
"Last-Translator: Edgar P. Burkhart <traduction@edgarpierre.fr>\n"
|
||||
"Language-Team: \n"
|
||||
|
@ -37,19 +37,19 @@ msgstr "Défaut"
|
|||
msgid "Accounts"
|
||||
msgstr "Comptes"
|
||||
|
||||
#: .\account\templates\account\account_detail.html:15
|
||||
#: .\account\templates\account\account_detail.html:13
|
||||
msgid "Edit account"
|
||||
msgstr "Modifier le compte"
|
||||
|
||||
#: .\account\templates\account\account_detail.html:17
|
||||
#: .\account\templates\account\account_detail.html:16
|
||||
msgid "Statements"
|
||||
msgstr "Relevés"
|
||||
|
||||
#: .\account\templates\account\account_detail.html:21
|
||||
#: .\account\templates\account\account_detail.html:20
|
||||
msgid "Transactions"
|
||||
msgstr "Transactions"
|
||||
|
||||
#: .\account\templates\account\account_detail.html:26
|
||||
#: .\account\templates\account\account_detail.html:25
|
||||
msgid "History"
|
||||
msgstr "Historique"
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
{% block title %}{{ object }} – {{ block.super }}{% endblock %}
|
||||
{% block link %}
|
||||
{{ block.super }}
|
||||
{% css "main/css/form.css" %}
|
||||
{% css "main/css/table.css" %}
|
||||
{% css "main/css/plot.css" %}
|
||||
{% endblock %}
|
||||
|
|
|
@ -24,31 +24,6 @@ class AccountUpdateView(NummiUpdateView):
|
|||
form_class = AccountForm
|
||||
pk_url_kwarg = "account"
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
_max = 8
|
||||
data = super().get_context_data(**kwargs)
|
||||
account = data["form"].instance
|
||||
|
||||
_transactions = account.transaction_set.all()
|
||||
if _transactions.count() > _max:
|
||||
data["transactions_url"] = reverse_lazy(
|
||||
"account_transactions", args=(account.pk,)
|
||||
)
|
||||
_statements = account.statement_set.all()
|
||||
if _statements.count() > _max:
|
||||
data["statements_url"] = reverse_lazy(
|
||||
"account_statements", args=(account.pk,)
|
||||
)
|
||||
|
||||
return data | {
|
||||
"transactions": _transactions[:8],
|
||||
"new_statement_url": reverse_lazy(
|
||||
"new_statement", kwargs={"account": account.pk}
|
||||
),
|
||||
"statements": _statements[:8],
|
||||
"history": history(account.transaction_set),
|
||||
}
|
||||
|
||||
|
||||
class AccountDeleteView(NummiDeleteView):
|
||||
model = Account
|
||||
|
|
Binary file not shown.
|
@ -7,7 +7,7 @@ msgid ""
|
|||
msgstr ""
|
||||
"Project-Id-Version: \n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2024-01-02 15:52+0100\n"
|
||||
"POT-Creation-Date: 2024-01-04 16:18+0100\n"
|
||||
"PO-Revision-Date: 2023-04-22 15:18+0200\n"
|
||||
"Last-Translator: Edgar P. Burkhart <traduction@edgarpierre.fr>\n"
|
||||
"Language-Team: \n"
|
||||
|
@ -38,6 +38,18 @@ msgstr "Budget"
|
|||
msgid "Categories"
|
||||
msgstr "Catégories"
|
||||
|
||||
#: .\category\templates\category\category_detail.html:12
|
||||
msgid "Edit category"
|
||||
msgstr "Modifier la catégorie"
|
||||
|
||||
#: .\category\templates\category\category_detail.html:15
|
||||
msgid "Transactions"
|
||||
msgstr "Transactions"
|
||||
|
||||
#: .\category\templates\category\category_detail.html:20
|
||||
msgid "History"
|
||||
msgstr "Historique"
|
||||
|
||||
#: .\category\templates\category\category_form.html:5
|
||||
msgid "Create category"
|
||||
msgstr "Créer une catégorie"
|
||||
|
@ -46,14 +58,6 @@ msgstr "Créer une catégorie"
|
|||
msgid "New category"
|
||||
msgstr "Nouvelle catégorie"
|
||||
|
||||
#: .\category\templates\category\category_form.html:13
|
||||
msgid "Transactions"
|
||||
msgstr "Transactions"
|
||||
|
||||
#: .\category\templates\category\category_form.html:18
|
||||
msgid "History"
|
||||
msgstr "Historique"
|
||||
|
||||
#: .\category\templates\category\category_plot.html:15
|
||||
msgid "Expenses"
|
||||
msgstr "Dépenses"
|
||||
|
|
24
nummi/category/templates/category/category_detail.html
Normal file
24
nummi/category/templates/category/category_detail.html
Normal file
|
@ -0,0 +1,24 @@
|
|||
{% extends "main/base.html" %}
|
||||
{% load main_extras i18n %}
|
||||
{% block title %}{{ object }} – {{ block.super }}{% endblock %}
|
||||
{% block link %}
|
||||
{{ block.super }}
|
||||
{% css "main/css/table.css" %}
|
||||
{% css "main/css/plot.css" %}
|
||||
{% endblock %}
|
||||
{% block body %}
|
||||
<h2>{{ object.icon|remix }}{{ object }}</h2>
|
||||
<p>
|
||||
<a href="{% url "edit_category" object.pk %}">{% translate "Edit category" %}</a>
|
||||
</p>
|
||||
<section>
|
||||
<h3>{% translate "Transactions" %}</h3>
|
||||
{% include "transaction/transaction_table.html" %}
|
||||
</section>
|
||||
{% if history %}
|
||||
<section>
|
||||
<h3>{% translate "History" %}</h3>
|
||||
{% include "history/plot.html" %}
|
||||
</section>
|
||||
{% endif %}
|
||||
{% endblock %}
|
|
@ -8,15 +8,3 @@
|
|||
{% translate "New category" %}
|
||||
{% endblock %}
|
||||
{% block h2 %}{{ form.instance.icon|remix }}{{ form.instance }}{% endblock %}
|
||||
{% block tables %}
|
||||
<section>
|
||||
<h3>{% translate "Transactions" %}</h3>
|
||||
{% include "transaction/transaction_table.html" %}
|
||||
</section>
|
||||
{% if history %}
|
||||
<section>
|
||||
<h3>{% translate "History" %}</h3>
|
||||
{% include "history/plot.html" %}
|
||||
</section>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{% load main_extras %}
|
||||
{% load main_extras category %}
|
||||
{% load i18n %}
|
||||
<div class="plot">
|
||||
<table class="full-width">
|
||||
|
@ -34,14 +34,14 @@
|
|||
<td class="c">
|
||||
{% if cat.category %}{{ cat.category__icon|remix }}{% endif %}
|
||||
</td>
|
||||
<td class="value">{{ cat.sum_m|pmrvalue }}</td>
|
||||
<td class="value">{{ cat.sum_m|pmvalue }}</td>
|
||||
<td class="bar m">
|
||||
{% if cat.sum_m %}
|
||||
<div style="width: {% widthratio cat.sum_m max -100 %}%"></div>
|
||||
{% endif %}
|
||||
{% if cat.sum < 0 %}
|
||||
<div class="tot" style="width:{% widthratio cat.sum max -100 %}%">
|
||||
<span>{{ cat.sum|pmrvalue }}</span>
|
||||
<span>{{ cat.sum|pmvalue }}</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
</td>
|
||||
|
@ -51,11 +51,11 @@
|
|||
{% endif %}
|
||||
{% if cat.sum > 0 %}
|
||||
<div class="tot" style="width:{% widthratio cat.sum max 100 %}%">
|
||||
<span>{{ cat.sum|pmrvalue }}</span>
|
||||
<span>{{ cat.sum|pmvalue }}</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td class="value">{{ cat.sum_p|pmrvalue }}</td>
|
||||
<td class="value">{{ cat.sum_p|pmvalue }}</td>
|
||||
</tr>
|
||||
{% empty %}
|
||||
<tr>
|
||||
|
@ -64,16 +64,16 @@
|
|||
{% endfor %}
|
||||
{% endspaceless %}
|
||||
</tbody>
|
||||
{% if categories %}
|
||||
<tfoot>
|
||||
<tfoot>
|
||||
{% if categories %}
|
||||
<tr>
|
||||
<th scope="row" colspan="2" class="l">{% translate "Total" %}</th>
|
||||
<td class="value">{{ total_m|pmrvalue }}</td>
|
||||
<td class="value">{{ total_m|pmvalue }}</td>
|
||||
<td class="bar m">
|
||||
<div style="width: {% widthratio total_m max -100 %}%"></div>
|
||||
{% if total < 0 %}
|
||||
<div class="tot" style="width:{% widthratio total max -100 %}%">
|
||||
<span>{{ total|pmrvalue }}</span>
|
||||
<span>{{ total|pmvalue }}</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
</td>
|
||||
|
@ -81,13 +81,35 @@
|
|||
<div style="width: {% widthratio total_p max 100 %}%"></div>
|
||||
{% if total > 0 %}
|
||||
<div class="tot" style="width:{% widthratio total max 100 %}%">
|
||||
<span>{{ total|pmrvalue }}</span>
|
||||
<span>{{ total|pmvalue }}</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td class="value">{{ total_p|pmrvalue }}</td>
|
||||
<td class="value">{{ total_p|pmvalue }}</td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% if statement %}
|
||||
<tr>
|
||||
<th scope="row" class="l">{% translate "Expected total" %}</th>
|
||||
<td class="c">{{ total|check:statement.diff }}</td>
|
||||
<td></td>
|
||||
<td class="bar m">
|
||||
{% if statement.diff < 0 %}
|
||||
<div class="tot" style="width:{% widthratio statement.diff max -100 %}%">
|
||||
<span>{{ statement.diff|pmvalue }}</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td class="bar p">
|
||||
{% if statement.diff >= 0 %}
|
||||
<div class="tot" style="width:{% widthratio statement.diff max 100 %}%">
|
||||
<span>{{ statement.diff|pmvalue }}</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
</tfoot>
|
||||
</table>
|
||||
</div>
|
||||
|
|
|
@ -1,15 +1,17 @@
|
|||
from django import template
|
||||
from django.db import models
|
||||
from django.db.models.functions import Greatest
|
||||
from main.templatetags.main_extras import remix
|
||||
|
||||
register = template.Library()
|
||||
|
||||
|
||||
@register.inclusion_tag("category/category_plot.html")
|
||||
def category_plot(transactions, **kwargs):
|
||||
def category_plot(transactions, budget=True, **kwargs):
|
||||
if budget:
|
||||
transactions = transactions.exclude(category__budget=False)
|
||||
categories = (
|
||||
transactions.exclude(category__budget=False)
|
||||
.values("category", "category__name", "category__icon")
|
||||
transactions.values("category", "category__name", "category__icon")
|
||||
.annotate(
|
||||
sum=models.Sum("value"),
|
||||
sum_m=models.Sum("value", filter=models.Q(value__lt=0)),
|
||||
|
@ -29,3 +31,13 @@ def category_plot(transactions, **kwargs):
|
|||
total=models.Sum("sum"),
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@register.filter
|
||||
def check(s, diff):
|
||||
if s is None:
|
||||
s = 0
|
||||
if s == diff:
|
||||
return remix("check", "green")
|
||||
else:
|
||||
return remix("close", "red")
|
||||
|
|
|
@ -5,7 +5,8 @@ from . import views
|
|||
|
||||
urlpatterns = [
|
||||
path("new", views.CategoryCreateView.as_view(), name="new_category"),
|
||||
path("<category>", views.CategoryUpdateView.as_view(), name="category"),
|
||||
path("<category>", views.CategoryDetailView.as_view(), name="category"),
|
||||
path("<category>/edit", views.CategoryUpdateView.as_view(), name="edit_category"),
|
||||
path(
|
||||
"<category>/transactions",
|
||||
views.CategoryTListView.as_view(),
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
from django.shortcuts import get_object_or_404
|
||||
from django.urls import reverse_lazy
|
||||
from history.utils import history
|
||||
from main.views import NummiCreateView, NummiDeleteView, NummiUpdateView
|
||||
from main.views import (
|
||||
NummiCreateView,
|
||||
NummiDeleteView,
|
||||
NummiDetailView,
|
||||
NummiUpdateView,
|
||||
)
|
||||
from transaction.views import TransactionListView
|
||||
|
||||
from .forms import CategoryForm
|
||||
|
@ -18,10 +23,15 @@ class CategoryUpdateView(NummiUpdateView):
|
|||
form_class = CategoryForm
|
||||
pk_url_kwarg = "category"
|
||||
|
||||
|
||||
class CategoryDetailView(NummiDetailView):
|
||||
model = Category
|
||||
pk_url_kwarg = "category"
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
_max = 8
|
||||
data = super().get_context_data(**kwargs)
|
||||
category = data["form"].instance
|
||||
category = data["object"]
|
||||
|
||||
data["transactions"] = category.transaction_set.all()[:_max]
|
||||
if len(data["transactions"]) == _max:
|
||||
|
|
|
@ -7,7 +7,7 @@ msgid ""
|
|||
msgstr ""
|
||||
"Project-Id-Version: \n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2024-01-04 16:04+0100\n"
|
||||
"POT-Creation-Date: 2024-01-04 16:18+0100\n"
|
||||
"PO-Revision-Date: 2023-04-23 08:03+0200\n"
|
||||
"Last-Translator: Edgar P. Burkhart <traduction@edgarpierre.fr>\n"
|
||||
"Language-Team: \n"
|
||||
|
@ -101,27 +101,27 @@ msgstr "Compte"
|
|||
msgid "Balance"
|
||||
msgstr "Solde"
|
||||
|
||||
#: .\main\templates\main\index.html:19 .\main\templates\main\index.html:30
|
||||
#: .\main\templates\main\index.html:19 .\main\templates\main\index.html:31
|
||||
msgid "Edit"
|
||||
msgstr "Modifier"
|
||||
|
||||
#: .\main\templates\main\index.html:34
|
||||
#: .\main\templates\main\index.html:36
|
||||
msgid "No account"
|
||||
msgstr "Aucun compte"
|
||||
|
||||
#: .\main\templates\main\index.html:41
|
||||
#: .\main\templates\main\index.html:43
|
||||
msgid "Create account"
|
||||
msgstr "Créer un compte"
|
||||
|
||||
#: .\main\templates\main\index.html:48
|
||||
#: .\main\templates\main\index.html:50
|
||||
msgid "Categories"
|
||||
msgstr "Catégories"
|
||||
|
||||
#: .\main\templates\main\index.html:54
|
||||
#: .\main\templates\main\index.html:56
|
||||
msgid "Create category"
|
||||
msgstr "Créer une catégorie"
|
||||
|
||||
#: .\main\templates\main\index.html:61
|
||||
#: .\main\templates\main\index.html:63
|
||||
msgid "History"
|
||||
msgstr "Historique"
|
||||
|
||||
|
|
|
@ -8,9 +8,9 @@ table.full-width col.bar {
|
|||
td.bar {
|
||||
position: relative;
|
||||
padding: 0;
|
||||
overflow: hidden;
|
||||
@media (width < 720px) {
|
||||
width: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
div {
|
||||
|
|
|
@ -8,16 +8,16 @@ register = template.Library()
|
|||
|
||||
@register.filter
|
||||
def value(val, pm=False, r=2):
|
||||
if not val:
|
||||
if val is None:
|
||||
return ""
|
||||
_prefix = ""
|
||||
_suffix = " €"
|
||||
_val = formats.number_format(round(val, r), r, use_l10n=True, force_grouping=True)
|
||||
_val = formats.number_format(val, decimal_pos=r, use_l10n=True, force_grouping=True)
|
||||
|
||||
if val > 0:
|
||||
if pm:
|
||||
_prefix += "+ "
|
||||
else:
|
||||
elif val < 0:
|
||||
_val = _val[1:]
|
||||
_prefix += "− "
|
||||
|
||||
|
@ -39,14 +39,6 @@ def remix(icon, cls=""):
|
|||
return mark_safe(f"""<span class="ri-{icon}-line {cls}"></span>""")
|
||||
|
||||
|
||||
@register.filter
|
||||
def check(sum, diff):
|
||||
if sum == diff:
|
||||
return remix("check", "green")
|
||||
else:
|
||||
return remix("close", "red")
|
||||
|
||||
|
||||
@register.filter
|
||||
def extension(file):
|
||||
return file.name.split(".")[-1].upper()
|
||||
|
|
|
@ -6,10 +6,7 @@
|
|||
{% block h2_new %}
|
||||
{% translate "New statement" %}
|
||||
{% endblock %}
|
||||
{% block h2 %}
|
||||
{{ form.instance.sum|check:form.instance.diff }}
|
||||
{{ form.instance }}
|
||||
{% endblock %}
|
||||
{% block h2 %}{{ form.instance }}{% endblock %}
|
||||
{% block pre %}
|
||||
{% if account %}
|
||||
<p>
|
||||
|
@ -21,10 +18,10 @@
|
|||
{% if not form.instance|adding %}
|
||||
<section>
|
||||
<h3>{% translate "Categories" %}</h3>
|
||||
{% category_plot transactions %}
|
||||
{% category_plot transactions budget=False statement=object %}
|
||||
</section>
|
||||
<section>
|
||||
<h3>{% translate "Transactions" %} ({{ form.instance.sum|pmvalue }} / {{ form.instance.diff|pmvalue }})</h3>
|
||||
<h3>{% translate "Transactions" %}</h3>
|
||||
{% include "transaction/transaction_table.html" %}
|
||||
</section>
|
||||
{% endif %}
|
||||
|
|
Loading…
Reference in a new issue