diff --git a/compensation/models.py b/compensation/models.py index 5367b2e2..c672714e 100644 --- a/compensation/models.py +++ b/compensation/models.py @@ -19,7 +19,7 @@ from codelist.settings import CODELIST_COMPENSATION_ACTION_ID, CODELIST_BIOTOPES CODELIST_COMPENSATION_FUNDING_ID from compensation.managers import CompensationStateManager, EcoAccountDeductionManager, CompensationActionManager, \ EcoAccountManager, CompensationManager -from compensation.utils.quality import CompensationQualityChecker +from compensation.utils.quality import CompensationQualityChecker, EcoAccountQualityChecker from intervention.models import Intervention, ResponsibilityData, LegalData from konova.models import BaseObject, BaseResource, Geometry, UuidModel, AbstractDocument, \ generate_document_file_upload_path @@ -447,17 +447,15 @@ class EcoAccount(AbstractCompensation): y, ) - def quality_check(self) -> list: + def quality_check(self) -> EcoAccountQualityChecker: """ Quality check Returns: - ret_msgs (list): Holds error messages + ret_msgs (EcoAccountQualityChecker): Holds validity and error messages """ - ret_msgs = [] - - # ToDo: Add check methods! - - return ret_msgs + checker = EcoAccountQualityChecker(self) + checker.run_check() + return checker def get_documents(self) -> QuerySet: """ Getter for all documents of an EcoAccount diff --git a/compensation/utils/quality.py b/compensation/utils/quality.py index 0e3c2cf0..28002db4 100644 --- a/compensation/utils/quality.py +++ b/compensation/utils/quality.py @@ -46,3 +46,59 @@ class CompensationQualityChecker(AbstractQualityChecker): """ if not self.obj.actions.all(): self._add_missing_attr_name(_con("Compensation", "Actions")) + + +class EcoAccountQualityChecker(CompensationQualityChecker): + def run_check(self): + """ Checks on data quality for an EcoAccount + + Returns: + + """ + self._check_deductable_surface() + self._check_responsible_data() + self._check_legal_data() + super().run_check() + + def _check_legal_data(self): + """ Checks the data quality for LegalData + + Returns: + + """ + try: + legal = self.obj.legal + if legal.registration_date is None: + self._add_missing_attr_name(_("Agreement date")) + except AttributeError: + self._add_missing_attr_name(_("Legal data")) + + def _check_deductable_surface(self): + """ Checks the quality of the deductable surface value + + Returns: + + """ + surface = self.obj.deductable_surface + if surface is None or surface == 0: + self._add_missing_attr_name(_("Available Surface")) + after_state_surface = self.obj.get_state_after_surface_sum() + if surface > after_state_surface: + self.messages.append( + _("Deductable surface can not be larger than state surface") + ) + + def _check_responsible_data(self): + """ Checks on responsible data quality + + Returns: + + """ + try: + resp = self.obj.responsible + if resp.conservation_office is None: + self._add_missing_attr_name(_("Conservation office")) + if resp.conservation_file_number is None or len(resp.conservation_file_number) == 0: + self._add_missing_attr_name(_("Conservation office file number")) + except AttributeError: + self._add_missing_attr_name(_("Responsible data")) diff --git a/ema/models.py b/ema/models.py index e8d31c4f..a0b5f5e7 100644 --- a/ema/models.py +++ b/ema/models.py @@ -6,8 +6,9 @@ from django.db.models import QuerySet from compensation.models import AbstractCompensation from ema.managers import EmaManager +from ema.utils.quality import EmaQualityChecker from konova.models import AbstractDocument, generate_document_file_upload_path -from konova.settings import DEFAULT_SRID_RLP, LANIS_LINK_TEMPLATE, EMA_DOC_PATH +from konova.settings import DEFAULT_SRID_RLP, LANIS_LINK_TEMPLATE from user.models import UserActionLogEntry @@ -80,17 +81,15 @@ class Ema(AbstractCompensation): y, ) - def quality_check(self) -> list: + def quality_check(self) -> EmaQualityChecker: """ Quality check Returns: - ret_msgs (list): Holds error messages + ret_msgs (EmaQualityChecker): Holds validity error messages """ - ret_msgs = [] - - # ToDo: Add check methods! - - return ret_msgs + checker = EmaQualityChecker(self) + checker.run_check() + return checker def get_documents(self) -> QuerySet: """ Getter for all documents of an EMA diff --git a/ema/utils/quality.py b/ema/utils/quality.py index 8c57f51f..dc7b07ca 100644 --- a/ema/utils/quality.py +++ b/ema/utils/quality.py @@ -5,16 +5,26 @@ Contact: michel.peltriaux@sgdnord.rlp.de Created on: 25.10.21 """ -from konova.utils.quality import AbstractQualityChecker +from django.utils.translation import gettext_lazy as _ +from compensation.utils.quality import CompensationQualityChecker -class EmaQualityChecker(AbstractQualityChecker): +class EmaQualityChecker(CompensationQualityChecker): def run_check(self): - """ Perform all defined data checks + super().run_check() + self._check_responsible_data() + + def _check_responsible_data(self): + """ Checks on responsible data quality Returns: """ - - self._check_geometry() - self.valid = len(self.messages) == 0 + try: + resp = self.obj.responsible + if resp.conservation_office is None: + self._add_missing_attr_name(_("Conservation office")) + if resp.conservation_file_number is None or len(resp.conservation_file_number) == 0: + self._add_missing_attr_name(_("Conservation office file number")) + except AttributeError: + self._add_missing_attr_name(_("Responsible data")) diff --git a/konova/forms.py b/konova/forms.py index 74e53896..83cf720a 100644 --- a/konova/forms.py +++ b/konova/forms.py @@ -472,13 +472,16 @@ class RecordModalForm(BaseModalForm): """ super_val = super().is_valid() - msgs = self.instance.quality_check() or [] - for msg in msgs: + if self.instance.recorded: + # If user wants to unrecord an already recorded dataset, we do not need to perform custom checks + return super_val + checker = self.instance.quality_check() + for msg in checker.messages: self.add_error( "confirm", msg ) - return super_val and (len(msgs) == 0) + return super_val and checker.valid def save(self): with transaction.atomic(): diff --git a/locale/de/LC_MESSAGES/django.mo b/locale/de/LC_MESSAGES/django.mo index f84bd186..817362f2 100644 Binary files a/locale/de/LC_MESSAGES/django.mo and b/locale/de/LC_MESSAGES/django.mo differ diff --git a/locale/de/LC_MESSAGES/django.po b/locale/de/LC_MESSAGES/django.po index a2995547..88d2ad0c 100644 --- a/locale/de/LC_MESSAGES/django.po +++ b/locale/de/LC_MESSAGES/django.po @@ -19,7 +19,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2021-10-25 13:37+0200\n" +"POT-Creation-Date: 2021-10-25 14:13+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -40,11 +40,11 @@ msgstr "Bis" #: analysis/forms.py:47 compensation/forms/forms.py:93 #: compensation/templates/compensation/detail/eco_account/view.html:58 #: compensation/templates/compensation/report/eco_account/report.html:16 -#: ema/templates/ema/detail/view.html:42 +#: compensation/utils/quality.py:100 ema/templates/ema/detail/view.html:42 #: ema/templates/ema/report/report.html:16 intervention/forms/forms.py:101 #: intervention/templates/intervention/detail/view.html:56 #: intervention/templates/intervention/report/report.html:37 -#: intervention/utils/quality.py:51 +#: intervention/utils/quality.py:49 msgid "Conservation office" msgstr "Eintragungsstelle" @@ -372,11 +372,11 @@ msgstr "Zusätzlicher Kommentar" #: compensation/forms/forms.py:109 #: compensation/templates/compensation/detail/eco_account/view.html:62 #: compensation/templates/compensation/report/eco_account/report.html:20 -#: ema/templates/ema/detail/view.html:46 +#: compensation/utils/quality.py:102 ema/templates/ema/detail/view.html:46 #: ema/templates/ema/report/report.html:20 intervention/forms/forms.py:129 #: intervention/templates/intervention/detail/view.html:60 #: intervention/templates/intervention/report/report.html:41 -#: intervention/utils/quality.py:44 +#: intervention/utils/quality.py:42 msgid "Conservation office file number" msgstr "Aktenzeichen Eintragungsstelle" @@ -414,7 +414,7 @@ msgstr "Neue Kompensation" msgid "Edit compensation" msgstr "Bearbeite Kompensation" -#: compensation/forms/forms.py:290 +#: compensation/forms/forms.py:290 compensation/utils/quality.py:84 msgid "Available Surface" msgstr "Verfügbare Fläche" @@ -424,6 +424,7 @@ msgstr "Die für Abbuchungen zur Verfügung stehende Menge" #: compensation/forms/forms.py:302 #: compensation/templates/compensation/detail/eco_account/view.html:66 +#: compensation/utils/quality.py:72 msgid "Agreement date" msgstr "Vereinbarungsdatum" @@ -804,6 +805,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 #: ema/templates/ema/detail/includes/states-after.html:8 msgid "States after" msgstr "Zielzustand" @@ -840,6 +842,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 #: ema/templates/ema/detail/includes/states-before.html:8 msgid "States before" msgstr "Ausgangszustand" @@ -1013,10 +1016,24 @@ msgstr "In LANIS öffnen" msgid "Deductions for" msgstr "Abbuchungen für" -#: compensation/utils/quality.py:35 +#: compensation/utils/quality.py:34 msgid "States unequal" msgstr "Ungleiche Zustandsflächenmengen" +#: compensation/utils/quality.py:74 intervention/utils/quality.py:84 +msgid "Legal data" +msgstr "Rechtliche Daten" + +#: compensation/utils/quality.py:88 +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 intervention/utils/quality.py:55 +msgid "Responsible data" +msgstr "Daten zu den verantwortlichen Stellen" + #: compensation/views/compensation_views.py:77 msgid "Compensation {} added" msgstr "Kompensation {} hinzugefügt" @@ -1165,7 +1182,7 @@ msgstr "Bauvorhaben XY; Flur ABC" #: intervention/forms/forms.py:51 #: intervention/templates/intervention/detail/view.html:35 #: intervention/templates/intervention/report/report.html:16 -#: intervention/utils/quality.py:84 +#: intervention/utils/quality.py:82 msgid "Process type" msgstr "Verfahrenstyp" @@ -1176,14 +1193,14 @@ msgstr "Mehrfachauswahl möglich" #: intervention/forms/forms.py:85 #: intervention/templates/intervention/detail/view.html:48 #: intervention/templates/intervention/report/report.html:29 -#: intervention/utils/quality.py:48 +#: intervention/utils/quality.py:46 msgid "Registration office" msgstr "Zulassungsbehörde" #: intervention/forms/forms.py:117 #: intervention/templates/intervention/detail/view.html:52 #: intervention/templates/intervention/report/report.html:33 -#: intervention/utils/quality.py:41 +#: intervention/utils/quality.py:39 msgid "Registration office file number" msgstr "Aktenzeichen Zulassungsbehörde" @@ -1194,7 +1211,7 @@ msgstr "" #: intervention/forms/forms.py:141 #: intervention/templates/intervention/detail/view.html:64 #: intervention/templates/intervention/report/report.html:45 -#: intervention/utils/quality.py:54 +#: intervention/utils/quality.py:52 msgid "Intervention handler" msgstr "Eingriffsverursacher" @@ -1205,7 +1222,7 @@ msgstr "Wer führt den Eingriff durch" #: intervention/forms/forms.py:154 #: intervention/templates/intervention/detail/view.html:96 #: intervention/templates/intervention/report/report.html:83 -#: intervention/utils/quality.py:75 +#: intervention/utils/quality.py:73 msgid "Registration date" msgstr "Datum Zulassung bzw. Satzungsbeschluss" @@ -1389,27 +1406,19 @@ msgstr "Abbuchungen von Ökokonten" msgid "Exist" msgstr "Vorhanden" -#: intervention/utils/quality.py:57 -msgid "Responsible data" -msgstr "Daten zu den verantwortlichen Stellen" - -#: intervention/utils/quality.py:72 +#: intervention/utils/quality.py:70 msgid "Revocation exists" msgstr "Widerspruch liegt vor" -#: intervention/utils/quality.py:78 +#: intervention/utils/quality.py:76 msgid "Binding date" msgstr "Datum Bestandskraft" -#: intervention/utils/quality.py:81 +#: intervention/utils/quality.py:79 msgid "Laws" msgstr "Gesetze" -#: intervention/utils/quality.py:86 -msgid "Legal data" -msgstr "Rechtliche Daten" - -#: intervention/utils/quality.py:100 +#: intervention/utils/quality.py:98 msgid "No compensation of any type found (Compensation, Payment, Deduction)" msgstr "" "Kein Ausgleich jeglicher Art gefunden (Kompensation, Ersatzzahlung, "