diff --git a/compensation/models.py b/compensation/models.py index 1d3e7cce..8c45bcf6 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 d085742e..6a003567 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 8a170bd7..ba577060 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 %}