#190 Mandatory finished deadline

* adds template message to indicate a finished-deadline is mandatory
* adds finished deadline existance to quality check of compensation-like entries
* adds proper warning to quality check result
* extends tests
pull/194/head
mpeltriaux 2 years ago
parent f717e650e6
commit 538d8d1ed2

@ -14,16 +14,14 @@ from user.models import User, Team
from django.db import models, transaction
from django.db.models import QuerySet, Sum
from django.http import HttpRequest
from django.utils.translation import gettext_lazy as _
from compensation.managers import CompensationManager
from compensation.models import CompensationState, CompensationAction
from compensation.utils.quality import CompensationQualityChecker
from konova.models import BaseObject, AbstractDocument, Deadline, generate_document_file_upload_path, \
GeoReferencedMixin
from konova.settings import DEFAULT_SRID_RLP, LANIS_LINK_TEMPLATE
GeoReferencedMixin, DeadlineType
from konova.utils.message_templates import DATA_UNSHARED_EXPLANATION, COMPENSATION_REMOVED_TEMPLATE, \
DOCUMENT_REMOVED_TEMPLATE, COMPENSATION_EDITED_TEMPLATE, DEADLINE_REMOVED, ADDED_DEADLINE, \
DOCUMENT_REMOVED_TEMPLATE, DEADLINE_REMOVED, ADDED_DEADLINE, \
COMPENSATION_ACTION_REMOVED, COMPENSATION_STATE_REMOVED, INTERVENTION_HAS_REVOCATIONS_TEMPLATE
from user.models import UserActionLogEntry
@ -226,6 +224,15 @@ class AbstractCompensation(BaseObject, GeoReferencedMixin):
request = self.set_geometry_conflict_message(request)
return request
def get_finished_deadlines(self):
""" Getter for FINISHED-deadlines
Returns:
queryset (QuerySet): The finished deadlines
"""
return self.deadlines.filter(
type=DeadlineType.FINISHED
)
class CEFMixin(models.Model):
""" Provides CEF flag as Mixin

@ -20,6 +20,11 @@
</div>
</div>
</div>
{% if not has_finished_deadlines %}
<div class="alert alert-danger mb-0">
{% trans 'Missing finished deadline ' %}
</div>
{% endif %}
<div class="card-body scroll-300 p-2">
<table class="table table-hover">
<thead>

@ -20,6 +20,11 @@
</div>
</div>
</div>
{% if not has_finished_deadlines %}
<div class="alert alert-danger mb-0">
{% trans 'Missing finished deadline ' %}
</div>
{% endif %}
<div class="card-body scroll-300 p-2">
<table class="table table-hover">
<thead>

@ -19,6 +19,7 @@ class CompensationQualityChecker(AbstractQualityChecker):
self._check_states()
self._check_actions()
self._check_geometry()
self._check_deadlines()
self.valid = len(self.messages) == 0
def _check_states(self):
@ -47,6 +48,16 @@ class CompensationQualityChecker(AbstractQualityChecker):
if not self.obj.actions.all():
self._add_missing_attr_name(_con("Compensation", "Actions"))
def _check_deadlines(self):
""" Checks data quality for related Deadline objects
Returns:
"""
finished_deadlines = self.obj.get_finished_deadlines()
if not finished_deadlines.exists():
self._add_missing_attr_name(_("Finished deadlines"))
class EcoAccountQualityChecker(CompensationQualityChecker):
def run_check(self):

@ -240,6 +240,7 @@ def detail_view(request: HttpRequest, id: str):
"is_ets_member": in_group(_user, ETS_GROUP),
"LANIS_LINK": comp.get_LANIS_link(),
TAB_TITLE_IDENTIFIER: f"{comp.identifier} - {comp.title}",
"has_finished_deadlines": comp.get_finished_deadlines().exists(),
}
context = BaseContext(request, context).context
return render(request, template, context)

@ -242,6 +242,7 @@ def detail_view(request: HttpRequest, id: str):
"deductions": deductions,
"actions": actions,
TAB_TITLE_IDENTIFIER: f"{acc.identifier} - {acc.title}",
"has_finished_deadlines": acc.get_finished_deadlines().exists(),
}
context = BaseContext(request, context).context
return render(request, template, context)

@ -20,6 +20,11 @@
</div>
</div>
</div>
{% if not has_finished_deadlines %}
<div class="alert alert-danger mb-0">
{% trans 'Missing finished deadline ' %}
</div>
{% endif %}
<div class="card-body scroll-300 p-2">
<table class="table table-hover">
<thead>

@ -166,6 +166,7 @@ def detail_view(request: HttpRequest, id: str):
"is_ets_member": in_group(_user, ETS_GROUP),
"LANIS_LINK": ema.get_LANIS_link(),
TAB_TITLE_IDENTIFIER: f"{ema.identifier} - {ema.title}",
"has_finished_deadlines": ema.get_finished_deadlines().exists(),
}
context = BaseContext(request, context).context
return render(request, template, context)

@ -22,7 +22,7 @@ from codelist.models import KonovaCode, KonovaCodeList
from compensation.models import Compensation, CompensationState, CompensationAction, EcoAccount, EcoAccountDeduction
from intervention.models import Legal, Responsibility, Intervention, Handler
from konova.management.commands.setup_data import GROUPS_DATA
from konova.models import Geometry
from konova.models import Geometry, Deadline, DeadlineType
from konova.settings import DEFAULT_GROUP
from konova.utils.generators import generate_random_string
from user.models import UserActionLogEntry
@ -41,6 +41,7 @@ class BaseTestCase(TestCase):
eco_account = None
comp_state = None
comp_action = None
finished_deadline = None
codes = None
superuser_pw = "root"
@ -69,6 +70,7 @@ class BaseTestCase(TestCase):
self.create_dummy_action()
self.codes = self.create_dummy_codes()
self.team = self.create_dummy_team()
self.finished_deadline = self.create_dummy_deadline()
# Set the default group as only group for the user
default_group = self.groups.get(name=DEFAULT_GROUP)
@ -279,6 +281,20 @@ class BaseTestCase(TestCase):
return team
def create_dummy_deadline(self, type: DeadlineType = DeadlineType.FINISHED):
""" Creates a dummy deadline.
If type is not specified, it defaults to DeadlineType.FINISHED
Returns:
deadline (Deadline): A deadline
"""
deadline = Deadline.objects.create(
type=type,
date="1970-01-01"
)
return deadline
@staticmethod
def create_dummy_geometry() -> MultiPolygon:
""" Creates some geometry
@ -361,6 +377,7 @@ class BaseTestCase(TestCase):
compensation.before_states.add(self.comp_state)
compensation.actions.add(self.comp_action)
compensation.geometry.geom = self.create_dummy_geometry()
compensation.deadlines.add(self.finished_deadline)
compensation.geometry.save()
return compensation
@ -390,6 +407,7 @@ class BaseTestCase(TestCase):
ema.before_states.add(self.comp_state)
ema.actions.add(self.comp_action)
ema.geometry.geom = self.create_dummy_geometry()
ema.deadlines.add(self.finished_deadline)
ema.geometry.save()
return ema
@ -410,6 +428,7 @@ class BaseTestCase(TestCase):
eco_account.geometry.geom = self.create_dummy_geometry()
eco_account.geometry.save()
eco_account.deductable_surface = eco_account.get_state_after_surface_sum()
eco_account.deadlines.add(self.finished_deadline)
eco_account.save()
return eco_account

Binary file not shown.

@ -26,7 +26,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-06-27 14:23+0200\n"
"POT-Creation-Date: 2022-08-08 14:39+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -55,7 +55,7 @@ msgstr "Einträge erstellt bis..."
#: analysis/forms.py:49 compensation/forms/forms.py:77
#: compensation/templates/compensation/detail/eco_account/view.html:59
#: compensation/templates/compensation/report/eco_account/report.html:16
#: compensation/utils/quality.py:100 ema/templates/ema/detail/view.html:49
#: compensation/utils/quality.py:113 ema/templates/ema/detail/view.html:49
#: ema/templates/ema/report/report.html:16 ema/utils/quality.py:26
#: intervention/forms/forms.py:102
#: intervention/templates/intervention/detail/view.html:56
@ -296,7 +296,7 @@ msgid "Law"
msgstr "Gesetz"
#: analysis/templates/analysis/reports/includes/old_data/amount.html:17
#: compensation/templates/compensation/detail/compensation/includes/deadlines.html:28
#: compensation/templates/compensation/detail/compensation/includes/deadlines.html:33
#: compensation/templates/compensation/detail/eco_account/includes/deadlines.html:28
#: ema/templates/ema/detail/includes/deadlines.html:28
msgid "Type"
@ -375,7 +375,7 @@ msgstr "Kompensation XY; Flur ABC"
#: compensation/forms/forms.py:57 compensation/forms/modalForms.py:63
#: compensation/forms/modalForms.py:361 compensation/forms/modalForms.py:469
#: compensation/templates/compensation/detail/compensation/includes/actions.html:35
#: compensation/templates/compensation/detail/compensation/includes/deadlines.html:34
#: compensation/templates/compensation/detail/compensation/includes/deadlines.html:39
#: compensation/templates/compensation/detail/compensation/includes/documents.html:34
#: compensation/templates/compensation/detail/eco_account/includes/actions.html:34
#: compensation/templates/compensation/detail/eco_account/includes/deadlines.html:34
@ -399,7 +399,7 @@ msgstr "Zusätzlicher Kommentar"
#: compensation/forms/forms.py:93
#: compensation/templates/compensation/detail/eco_account/view.html:63
#: compensation/templates/compensation/report/eco_account/report.html:20
#: compensation/utils/quality.py:102 ema/templates/ema/detail/view.html:53
#: compensation/utils/quality.py:115 ema/templates/ema/detail/view.html:53
#: ema/templates/ema/report/report.html:20 ema/utils/quality.py:28
#: intervention/forms/forms.py:130
#: intervention/templates/intervention/detail/view.html:60
@ -485,7 +485,7 @@ msgstr "Neue Kompensation"
msgid "Edit compensation"
msgstr "Bearbeite Kompensation"
#: compensation/forms/forms.py:356 compensation/utils/quality.py:84
#: compensation/forms/forms.py:356 compensation/utils/quality.py:97
msgid "Available Surface"
msgstr "Verfügbare Fläche"
@ -495,7 +495,7 @@ msgstr "Die für Abbuchungen zur Verfügung stehende Menge"
#: compensation/forms/forms.py:368
#: compensation/templates/compensation/detail/eco_account/view.html:67
#: compensation/utils/quality.py:72
#: compensation/utils/quality.py:85
msgid "Agreement date"
msgstr "Vereinbarungsdatum"
@ -597,7 +597,7 @@ msgid "Select the deadline type"
msgstr "Fristart wählen"
#: compensation/forms/modalForms.py:345
#: compensation/templates/compensation/detail/compensation/includes/deadlines.html:31
#: compensation/templates/compensation/detail/compensation/includes/deadlines.html:36
#: compensation/templates/compensation/detail/eco_account/includes/deadlines.html:31
#: ema/templates/ema/detail/includes/deadlines.html:31
#: intervention/forms/modalForms.py:149
@ -617,7 +617,7 @@ msgid "Insert data for the new deadline"
msgstr "Geben Sie die Daten der neuen Frist ein"
#: compensation/forms/modalForms.py:389
#: compensation/templates/compensation/detail/compensation/includes/deadlines.html:59
#: compensation/templates/compensation/detail/compensation/includes/deadlines.html:64
#: compensation/templates/compensation/detail/eco_account/includes/deadlines.html:57
#: ema/templates/ema/detail/includes/deadlines.html:57
msgid "Edit deadline"
@ -798,7 +798,7 @@ msgid "Amount"
msgstr "Menge"
#: compensation/templates/compensation/detail/compensation/includes/actions.html:40
#: compensation/templates/compensation/detail/compensation/includes/deadlines.html:39
#: compensation/templates/compensation/detail/compensation/includes/deadlines.html:44
#: compensation/templates/compensation/detail/compensation/includes/documents.html:39
#: compensation/templates/compensation/detail/compensation/includes/states-after.html:41
#: compensation/templates/compensation/detail/compensation/includes/states-before.html:41
@ -882,7 +882,11 @@ msgstr "Termine und Fristen"
msgid "Add new deadline"
msgstr "Frist/Termin hinzufügen"
#: compensation/templates/compensation/detail/compensation/includes/deadlines.html:62
#: compensation/templates/compensation/detail/compensation/includes/deadlines.html:25
msgid "Missing finished deadline "
msgstr "Umsetzungstermin fehlt"
#: compensation/templates/compensation/detail/compensation/includes/deadlines.html:67
#: compensation/templates/compensation/detail/eco_account/includes/deadlines.html:60
#: ema/templates/ema/detail/includes/deadlines.html:60
msgid "Remove deadline"
@ -928,7 +932,7 @@ msgstr "Dokument löschen"
#: compensation/templates/compensation/detail/compensation/includes/states-after.html:8
#: compensation/templates/compensation/detail/eco_account/includes/states-after.html:8
#: compensation/utils/quality.py:39
#: compensation/utils/quality.py:42
#: ema/templates/ema/detail/includes/states-after.html:8
msgid "States after"
msgstr "Zielzustand"
@ -974,7 +978,7 @@ msgstr "Zustand entfernen"
#: compensation/templates/compensation/detail/compensation/includes/states-before.html:8
#: compensation/templates/compensation/detail/eco_account/includes/states-before.html:8
#: compensation/utils/quality.py:37
#: compensation/utils/quality.py:40
#: ema/templates/ema/detail/includes/states-before.html:8
msgid "States before"
msgstr "Ausgangszustand"
@ -1067,6 +1071,24 @@ msgstr "Zuletzt bearbeitet"
msgid "Shared with"
msgstr "Freigegeben für"
#: compensation/templates/compensation/detail/compensation/view.html:132
#: compensation/templates/compensation/detail/eco_account/view.html:110
#: ema/templates/ema/detail/view.html:96
#: intervention/templates/intervention/detail/view.html:138
msgid ""
"The data must be shared with you, if you want to see which other users have "
"shared access as well."
msgstr ""
"Die Daten müssen für Sie freigegeben sein, damit Sie sehen können welche "
"weiteren Nutzern ebenfalls Zugriff hierauf haben."
#: compensation/templates/compensation/detail/compensation/view.html:134
#: compensation/templates/compensation/detail/eco_account/view.html:112
#: ema/templates/ema/detail/view.html:98
#: intervention/templates/intervention/detail/view.html:140
msgid "other users"
msgstr "weitere Nutzer"
#: compensation/templates/compensation/detail/eco_account/includes/controls.html:15
#: ema/templates/ema/detail/includes/controls.html:15
#: intervention/forms/modalForms.py:71
@ -1166,21 +1188,25 @@ msgstr "Abbuchungen für"
msgid "None"
msgstr "-"
#: compensation/utils/quality.py:34
#: compensation/utils/quality.py:37
msgid "States unequal"
msgstr "Ungleiche Zustandsflächenmengen"
#: compensation/utils/quality.py:74 intervention/utils/quality.py:84
#: compensation/utils/quality.py:61
msgid "Finished deadlines"
msgstr "Umsetzungstermin"
#: compensation/utils/quality.py:87 intervention/utils/quality.py:84
msgid "Legal data"
msgstr "Rechtliche Daten"
#: compensation/utils/quality.py:88
#: compensation/utils/quality.py:101
msgid "Deductable surface can not be larger than state surface"
msgstr ""
"Die abbuchbare Fläche darf die Gesamtfläche der Zielzustände nicht "
"überschreiten"
#: compensation/utils/quality.py:104 ema/utils/quality.py:30
#: compensation/utils/quality.py:117 ema/utils/quality.py:30
#: intervention/utils/quality.py:55
msgid "Responsible data"
msgstr "Daten zu den verantwortlichen Stellen"
@ -1198,12 +1224,12 @@ msgstr "Kompensation {} bearbeitet"
msgid "Edit {}"
msgstr "Bearbeite {}"
#: compensation/views/compensation.py:268 compensation/views/eco_account.py:359
#: compensation/views/compensation.py:269 compensation/views/eco_account.py:359
#: ema/views.py:194 intervention/views.py:542
msgid "Log"
msgstr "Log"
#: compensation/views/compensation.py:612 compensation/views/eco_account.py:727
#: compensation/views/compensation.py:613 compensation/views/eco_account.py:727
#: ema/views.py:558 intervention/views.py:688
msgid "Report {}"
msgstr "Bericht {}"
@ -1549,18 +1575,6 @@ msgstr "Eingriffsverursacher"
msgid "Exists"
msgstr "vorhanden"
#: intervention/templates/intervention/detail/view.html:138
msgid ""
"The data must be shared with you, if you want to see which other users have "
"shared access as well."
msgstr ""
"Die Daten müssen für Sie freigegeben sein, damit Sie sehen können welche weiteren Nutzern "
"ebenfalls Zugriff hierauf haben."
#: intervention/templates/intervention/detail/view.html:140
msgid "other users"
msgstr "weitere Nutzer"
#: intervention/templates/intervention/report/report.html:58
msgid "Deductions of eco-accounts"
msgstr "Abbuchungen von Ökokonten"
@ -2753,7 +2767,7 @@ msgstr "Benachrichtigungen"
msgid "Manage teams"
msgstr ""
#: user/templates/user/index.html:61 user/templates/user/team/index.html:18
#: user/templates/user/index.html:61 user/templates/user/team/index.html:19
#: user/views.py:167
msgid "Teams"
msgstr ""

Loading…
Cancel
Save