From 280510d72953a2a5d464e8bdf0dce35bfc23f823 Mon Sep 17 00:00:00 2001 From: mipel Date: Thu, 26 Aug 2021 15:45:24 +0200 Subject: [PATCH] [EcoAccount] See recorded state of withdraw #6 * adds prefiltering of withdraws --> excludes withdraws of as deleted flagged interventions * renders intervention-recorded icon into eco account withdraws details view * fixes bug in case of document deleting which does not contain any files * renames RecordForm into RecordModalForm for more clarity --- compensation/models.py | 4 +++- .../eco_account/includes/withdraws.html | 19 +++++++++++++------ compensation/views/eco_account_views.py | 9 +++++++-- ema/views.py | 4 ++-- intervention/forms.py | 2 ++ intervention/models.py | 15 ++++++++++++++- intervention/views.py | 4 ++-- konova/forms.py | 4 +++- 8 files changed, 46 insertions(+), 15 deletions(-) diff --git a/compensation/models.py b/compensation/models.py index 840cb82..6f05ba5 100644 --- a/compensation/models.py +++ b/compensation/models.py @@ -239,7 +239,9 @@ class EcoAccount(AbstractCompensation): """ ret_val = 0 - withdraws = self.withdraws.all() + withdraws = self.withdraws.filter( + intervention__deleted=None, + ) withdraw_surfaces = withdraws.aggregate(Sum("surface"))["surface__sum"] or 0 after_states_surfaces = self.after_states.all().aggregate(Sum("surface"))["surface__sum"] or withdraw_surfaces ## no division by zero ret_val = after_states_surfaces - withdraw_surfaces diff --git a/compensation/templates/compensation/detail/eco_account/includes/withdraws.html b/compensation/templates/compensation/detail/eco_account/includes/withdraws.html index 5916283..19fe679 100644 --- a/compensation/templates/compensation/detail/eco_account/includes/withdraws.html +++ b/compensation/templates/compensation/detail/eco_account/includes/withdraws.html @@ -4,7 +4,7 @@
- {{obj.withdraws.count}} + {{withdraws.count}} {% trans 'Eco Account Withdraws' %}
@@ -27,6 +27,9 @@ {% trans 'Intervention Identifier' %} + + {% trans 'Recorded' %} + {% trans 'Amount' %} @@ -39,16 +42,20 @@ - {% for withdraw in obj.withdraws.all %} - + {% for withdraw in withdraws %} + - {% if withdraw.account.deleted or not withdraw.account.recorded %} - {% fa5_icon 'exclamation-triangle' %} - {% endif %} {{ withdraw.intervention.identifier }} + + {% if withdraw.intervention.recorded %} + + {% else %} + + {% endif %} + {{ withdraw.surface|floatformat:2|intcomma }} m² {{ withdraw.created.timestamp|default_if_none:""|naturalday}} diff --git a/compensation/views/eco_account_views.py b/compensation/views/eco_account_views.py index 767e932..282717f 100644 --- a/compensation/views/eco_account_views.py +++ b/compensation/views/eco_account_views.py @@ -19,7 +19,7 @@ from compensation.tables import EcoAccountTable from intervention.forms import NewWithdrawForm from konova.contexts import BaseContext from konova.decorators import any_group_check, default_group_required, conservation_office_group_required -from konova.forms import RemoveModalForm, SimpleGeomForm, NewDocumentForm, RecordForm +from konova.forms import RemoveModalForm, SimpleGeomForm, NewDocumentForm, RecordModalForm from konova.settings import DEFAULT_GROUP, ZB_GROUP, ETS_GROUP from konova.utils.user_checks import in_group @@ -97,6 +97,10 @@ def open_view(request: HttpRequest, id: str): # Calculate rest of available surface for withdraws available = acc.get_available_rest(as_percentage=True) + withdraws = acc.withdraws.filter( + intervention__deleted=None, + ) + context = { "obj": acc, "geom_form": geom_form, @@ -111,6 +115,7 @@ def open_view(request: HttpRequest, id: str): "is_zb_member": in_group(_user, ZB_GROUP), "is_ets_member": in_group(_user, ETS_GROUP), "LANIS_LINK": acc.get_LANIS_link(), + "withdraws": withdraws, } context = BaseContext(request, context).context return render(request, template, context) @@ -200,7 +205,7 @@ def record_view(request: HttpRequest, id:str): """ acc = get_object_or_404(EcoAccount, id=id) - form = RecordForm(request.POST or None, instance=acc, user=request.user) + form = RecordModalForm(request.POST or None, instance=acc, user=request.user) msg_succ = _("{} unrecorded") if acc.recorded else _("{} recorded") msg_succ = msg_succ.format(acc.identifier) return form.process_request( diff --git a/ema/views.py b/ema/views.py index 3110330..df347de 100644 --- a/ema/views.py +++ b/ema/views.py @@ -11,7 +11,7 @@ from ema.tables import EmaTable from konova.contexts import BaseContext from konova.decorators import conservation_office_group_required from ema.models import Ema -from konova.forms import RemoveModalForm, NewDocumentForm, SimpleGeomForm, RecordForm +from konova.forms import RemoveModalForm, NewDocumentForm, SimpleGeomForm, RecordModalForm from konova.settings import DEFAULT_GROUP, ZB_GROUP, ETS_GROUP from konova.utils.user_checks import in_group @@ -168,7 +168,7 @@ def record_view(request: HttpRequest, id: str): """ ema = get_object_or_404(Ema, id=id) msg_succ = _("{} unrecorded") if ema.recorded else _("{} recorded") - form = RecordForm(request.POST or None, instance=ema, user=request.user) + form = RecordModalForm(request.POST or None, instance=ema, user=request.user) return form.process_request( request=request, msg_success=msg_succ.format("EMA"), diff --git a/intervention/forms.py b/intervention/forms.py index 82993b9..c7032f7 100644 --- a/intervention/forms.py +++ b/intervention/forms.py @@ -413,6 +413,8 @@ class RunCheckForm(BaseModalForm): super().__init__(*args, **kwargs) self.form_title = _("Run check") self.form_caption = _("I, {} {}, confirm that all necessary control steps have been performed by myself.").format(self.user.first_name, self.user.last_name) + # Disable automatic w-100 setting for this type of modal form. Looks kinda strange + self.fields["confirm"].widget.attrs["class"] = "" def is_valid(self): super_result = super().is_valid() diff --git a/intervention/models.py b/intervention/models.py index 22bbf94..c583784 100644 --- a/intervention/models.py +++ b/intervention/models.py @@ -7,10 +7,12 @@ Created on: 17.11.20 """ from django.contrib.auth.models import User from django.contrib.gis.db import models +from django.utils.timezone import localtime from django.utils.translation import gettext_lazy as _ from konova.models import BaseObject, Geometry, UuidModel, BaseResource from konova.settings import DEFAULT_SRID_RLP, LANIS_LINK_TEMPLATE +from konova.sub_settings.django_settings import DEFAULT_DATE_TIME_FORMAT from konova.utils import generators from organisation.models import Organisation from user.models import UserActionLogEntry @@ -45,7 +47,8 @@ class Revocation(BaseResource): def delete(self): # Make sure related objects are being removed as well - self.document.delete() + if self.document: + self.document.delete() super().delete() @@ -248,3 +251,13 @@ class Intervention(BaseObject): x, y, ) + + @property + def recorded_tooltip(self): + tooltip = _("Not recorded yet") + if self.recorded: + value = self.recorded.timestamp + value = localtime(value) + on = value.strftime(DEFAULT_DATE_TIME_FORMAT) + tooltip = _("Recorded on {} by {}").format(on, self.recorded.user) + return tooltip \ No newline at end of file diff --git a/intervention/views.py b/intervention/views.py index c9fb34e..7e1531a 100644 --- a/intervention/views.py +++ b/intervention/views.py @@ -10,7 +10,7 @@ from intervention.models import Intervention, Revocation from intervention.tables import InterventionTable from konova.contexts import BaseContext from konova.decorators import * -from konova.forms import SimpleGeomForm, NewDocumentForm, RemoveModalForm, RecordForm +from konova.forms import SimpleGeomForm, NewDocumentForm, RemoveModalForm, RecordModalForm from konova.sub_settings.django_settings import DEFAULT_DATE_FORMAT from konova.utils.message_templates import FORM_INVALID, INTERVENTION_INVALID from konova.utils.user_checks import in_group @@ -372,7 +372,7 @@ def record_view(request: HttpRequest, id: str): """ intervention = get_object_or_404(Intervention, id=id) - form = RecordForm(request.POST or None, instance=intervention, user=request.user) + form = RecordModalForm(request.POST or None, instance=intervention, user=request.user) msg_succ = _("{} unrecorded") if intervention.recorded else _("{} recorded") msg_succ = msg_succ.format(intervention.identifier) return form.process_request( diff --git a/konova/forms.py b/konova/forms.py index bff7bc1..2ea9f57 100644 --- a/konova/forms.py +++ b/konova/forms.py @@ -359,7 +359,7 @@ class NewDocumentForm(BaseModalForm): return doc -class RecordForm(BaseModalForm): +class RecordModalForm(BaseModalForm): """ Modal form for recording data """ @@ -374,6 +374,8 @@ class RecordForm(BaseModalForm): super().__init__(*args, **kwargs) self.form_title = _("Record data") self.form_caption = _("I, {} {}, confirm that all necessary control steps have been performed by myself.").format(self.user.first_name, self.user.last_name) + # Disable automatic w-100 setting for this type of modal form. Looks kinda strange + self.fields["confirm"].widget.attrs["class"] = "" if self.instance.recorded: # unrecord!