From f8b3e5c8fd92dc7c4759c10aa5dd342591db29a1 Mon Sep 17 00:00:00 2001 From: mipel Date: Tue, 10 Aug 2021 10:42:04 +0200 Subject: [PATCH] EcoAccount withdraws * adds functionality for withdraws from eco accounts in detail view of interventions and eco account as well * adds get_surface() method to AbstractCompensation class to provide a simple getter for a sql calculation * adds get_surface_withdraws() method to EcoAccount class to provide a simple getter for a sql calculation * renames some routes to match coherent rout naming * adds logic check on NewWithdrawForm * renames templates/table directory to templates/form, since there are form-table templates inside --> more clarity * adds new autocomplete routes to konova/urls.py for Interventions and EcoAccounts * adds/updates translations * adds/updates template comments * updates requirements.txt --- compensation/models.py | 21 +- .../eco_account/includes/withdraws.html | 14 +- compensation/urls.py | 1 + compensation/views/eco_account_views.py | 26 ++- intervention/forms.py | 124 +++++++++++ .../detail/includes/revocation.html | 4 +- .../detail/includes/withdraws.html | 14 +- intervention/urls.py | 9 +- intervention/views.py | 22 +- konova/autocompletes.py | 38 ++++ konova/templates/konova/form.html | 2 +- konova/urls.py | 5 +- locale/de/LC_MESSAGES/django.mo | Bin 16199 -> 16955 bytes locale/de/LC_MESSAGES/django.po | 205 ++++++++++-------- requirements.txt | 2 +- templates/base.html | 3 +- templates/footer.html | 11 + .../{table => form}/generic_table_form.html | 2 +- .../generic_table_form_body.html | 0 templates/modal/modal_form.html | 4 +- user/templates/user/notifications.html | 2 +- 21 files changed, 388 insertions(+), 121 deletions(-) rename templates/{table => form}/generic_table_form.html (93%) rename templates/{table => form}/generic_table_form_body.html (100%) diff --git a/compensation/models.py b/compensation/models.py index 1d3e7cc..8c45bcf 100644 --- a/compensation/models.py +++ b/compensation/models.py @@ -7,9 +7,8 @@ Created on: 17.11.20 """ from django.contrib.auth.models import User from django.contrib.gis.db import models -from django.core.validators import MinValueValidator, MaxValueValidator -from django.db import transaction -from django.utils import timezone +from django.core.validators import MinValueValidator +from django.db.models import Sum from django.utils.timezone import now from django.utils.translation import gettext_lazy as _ @@ -121,6 +120,14 @@ class AbstractCompensation(BaseObject): class Meta: abstract = True + def get_surface(self) -> float: + """ Calculates the compensation's/account's surface + + Returns: + sum_surface (float) + """ + return self.after_states.all().aggregate(Sum("surface"))["surface__sum"] + class Compensation(AbstractCompensation): """ @@ -188,6 +195,14 @@ class EcoAccount(AbstractCompensation): def __str__(self): return "{}".format(self.identifier) + def get_surface_withdraws(self) -> float: + """ Calculates the compensation's/account's surface + + Returns: + sum_surface (float) + """ + return self.withdraws.all().aggregate(Sum("surface"))["surface__sum"] + class EcoAccountWithdraw(BaseResource): """ diff --git a/compensation/templates/compensation/detail/eco_account/includes/withdraws.html b/compensation/templates/compensation/detail/eco_account/includes/withdraws.html index d085742..6a00356 100644 --- a/compensation/templates/compensation/detail/eco_account/includes/withdraws.html +++ b/compensation/templates/compensation/detail/eco_account/includes/withdraws.html @@ -11,12 +11,10 @@
{% if is_default_member and has_access %} - - - + {% endif %}
@@ -32,6 +30,9 @@ {% trans 'Amount' %} + + {% trans 'Created' %} + {% trans 'Action' %} @@ -46,6 +47,7 @@ {{ withdraw.surface|floatformat:2|intcomma }} m² + {{ withdraw.created.timestamp|default_if_none:""|naturalday}} {% if is_default_member and has_access %} @@ -56,7 +56,7 @@ {% if is_default_member and has_access %} - {% endif %} diff --git a/intervention/templates/intervention/detail/includes/withdraws.html b/intervention/templates/intervention/detail/includes/withdraws.html index 8a170bd..ba57706 100644 --- a/intervention/templates/intervention/detail/includes/withdraws.html +++ b/intervention/templates/intervention/detail/includes/withdraws.html @@ -11,12 +11,10 @@
{% if is_default_member and has_access %} - - - + {% endif %}
@@ -32,6 +30,9 @@ {% trans 'Amount' %} + + {% trans 'Created' %} + {% trans 'Action' %} @@ -49,6 +50,7 @@ {{ withdraw.surface|floatformat:2|intcomma }} m² + {{ withdraw.created.timestamp|default_if_none:""|naturalday}} {% if is_default_member and has_access %}