diff --git a/nummi/account/locale/fr_FR/LC_MESSAGES/django.po b/nummi/account/locale/fr_FR/LC_MESSAGES/django.po index e0baa15..14f7e1a 100644 --- a/nummi/account/locale/fr_FR/LC_MESSAGES/django.po +++ b/nummi/account/locale/fr_FR/LC_MESSAGES/django.po @@ -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 \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" diff --git a/nummi/account/templates/account/account_detail.html b/nummi/account/templates/account/account_detail.html index 419669e..92c3c7f 100644 --- a/nummi/account/templates/account/account_detail.html +++ b/nummi/account/templates/account/account_detail.html @@ -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 %} diff --git a/nummi/account/views.py b/nummi/account/views.py index a07bd8b..902db10 100644 --- a/nummi/account/views.py +++ b/nummi/account/views.py @@ -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 diff --git a/nummi/category/locale/fr_FR/LC_MESSAGES/django.mo b/nummi/category/locale/fr_FR/LC_MESSAGES/django.mo index 32338f9..53d58b5 100644 Binary files a/nummi/category/locale/fr_FR/LC_MESSAGES/django.mo and b/nummi/category/locale/fr_FR/LC_MESSAGES/django.mo differ diff --git a/nummi/category/locale/fr_FR/LC_MESSAGES/django.po b/nummi/category/locale/fr_FR/LC_MESSAGES/django.po index d59e917..d66c030 100644 --- a/nummi/category/locale/fr_FR/LC_MESSAGES/django.po +++ b/nummi/category/locale/fr_FR/LC_MESSAGES/django.po @@ -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 \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" diff --git a/nummi/category/templates/category/category_detail.html b/nummi/category/templates/category/category_detail.html new file mode 100644 index 0000000..b0ea18f --- /dev/null +++ b/nummi/category/templates/category/category_detail.html @@ -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 %} +

{{ object.icon|remix }}{{ object }}

+

+ {% translate "Edit category" %} +

+
+

{% translate "Transactions" %}

+ {% include "transaction/transaction_table.html" %} +
+ {% if history %} +
+

{% translate "History" %}

+ {% include "history/plot.html" %} +
+ {% endif %} +{% endblock %} diff --git a/nummi/category/templates/category/category_form.html b/nummi/category/templates/category/category_form.html index f4aaa6d..7e2748e 100644 --- a/nummi/category/templates/category/category_form.html +++ b/nummi/category/templates/category/category_form.html @@ -8,15 +8,3 @@ {% translate "New category" %} {% endblock %} {% block h2 %}{{ form.instance.icon|remix }}{{ form.instance }}{% endblock %} -{% block tables %} -
-

{% translate "Transactions" %}

- {% include "transaction/transaction_table.html" %} -
- {% if history %} -
-

{% translate "History" %}

- {% include "history/plot.html" %} -
- {% endif %} -{% endblock %} diff --git a/nummi/category/templates/category/category_plot.html b/nummi/category/templates/category/category_plot.html index 63577af..c152c10 100644 --- a/nummi/category/templates/category/category_plot.html +++ b/nummi/category/templates/category/category_plot.html @@ -1,4 +1,4 @@ -{% load main_extras %} +{% load main_extras category %} {% load i18n %}
@@ -34,14 +34,14 @@ - + @@ -51,11 +51,11 @@ {% endif %} {% if cat.sum > 0 %}
- {{ cat.sum|pmrvalue }} + {{ cat.sum|pmvalue }}
{% endif %} - + {% empty %} @@ -64,16 +64,16 @@ {% endfor %} {% endspaceless %} - {% if categories %} - + + {% if categories %} - + @@ -81,13 +81,35 @@
{% if total > 0 %}
- {{ total|pmrvalue }} + {{ total|pmvalue }}
{% endif %} - + - - {% endif %} + {% endif %} + {% if statement %} + + + + + + + + + {% endif %} +
{% if cat.category %}{{ cat.category__icon|remix }}{% endif %} {{ cat.sum_m|pmrvalue }}{{ cat.sum_m|pmvalue }} {% if cat.sum_m %}
{% endif %} {% if cat.sum < 0 %}
- {{ cat.sum|pmrvalue }} + {{ cat.sum|pmvalue }}
{% endif %}
{{ cat.sum_p|pmrvalue }}{{ cat.sum_p|pmvalue }}
{% translate "Total" %}{{ total_m|pmrvalue }}{{ total_m|pmvalue }}
{% if total < 0 %}
- {{ total|pmrvalue }} + {{ total|pmvalue }}
{% endif %}
{{ total_p|pmrvalue }}{{ total_p|pmvalue }}
{% translate "Expected total" %}{{ total|check:statement.diff }} + {% if statement.diff < 0 %} +
+ {{ statement.diff|pmvalue }} +
+ {% endif %} +
+ {% if statement.diff >= 0 %} +
+ {{ statement.diff|pmvalue }} +
+ {% endif %} +
diff --git a/nummi/category/templatetags/category.py b/nummi/category/templatetags/category.py index 5f76341..aaf3bf9 100644 --- a/nummi/category/templatetags/category.py +++ b/nummi/category/templatetags/category.py @@ -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") diff --git a/nummi/category/urls.py b/nummi/category/urls.py index 64b8ae9..9936065 100644 --- a/nummi/category/urls.py +++ b/nummi/category/urls.py @@ -5,7 +5,8 @@ from . import views urlpatterns = [ path("new", views.CategoryCreateView.as_view(), name="new_category"), - path("", views.CategoryUpdateView.as_view(), name="category"), + path("", views.CategoryDetailView.as_view(), name="category"), + path("/edit", views.CategoryUpdateView.as_view(), name="edit_category"), path( "/transactions", views.CategoryTListView.as_view(), diff --git a/nummi/category/views.py b/nummi/category/views.py index 36fe0d0..f01d908 100644 --- a/nummi/category/views.py +++ b/nummi/category/views.py @@ -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: diff --git a/nummi/main/locale/fr_FR/LC_MESSAGES/django.po b/nummi/main/locale/fr_FR/LC_MESSAGES/django.po index fbf05c3..4ff140a 100644 --- a/nummi/main/locale/fr_FR/LC_MESSAGES/django.po +++ b/nummi/main/locale/fr_FR/LC_MESSAGES/django.po @@ -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 \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" diff --git a/nummi/main/static/main/css/plot.css b/nummi/main/static/main/css/plot.css index 9a2bc7a..4a9eb36 100644 --- a/nummi/main/static/main/css/plot.css +++ b/nummi/main/static/main/css/plot.css @@ -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 { diff --git a/nummi/main/templatetags/main_extras.py b/nummi/main/templatetags/main_extras.py index a85d8db..fd29a10 100644 --- a/nummi/main/templatetags/main_extras.py +++ b/nummi/main/templatetags/main_extras.py @@ -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"""""") -@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() diff --git a/nummi/statement/templates/statement/statement_form.html b/nummi/statement/templates/statement/statement_form.html index b09e993..f5e04c8 100644 --- a/nummi/statement/templates/statement/statement_form.html +++ b/nummi/statement/templates/statement/statement_form.html @@ -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 %}

@@ -21,10 +18,10 @@ {% if not form.instance|adding %}

{% translate "Categories" %}

- {% category_plot transactions %} + {% category_plot transactions budget=False statement=object %}
-

{% translate "Transactions" %} ({{ form.instance.sum|pmvalue }} / {{ form.instance.diff|pmvalue }})

+

{% translate "Transactions" %}

{% include "transaction/transaction_table.html" %}
{% endif %}