You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
konova/compensation/utils/quality.py

105 lines
3.1 KiB
Python

"""
Author: Michel Peltriaux
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
Contact: michel.peltriaux@sgdnord.rlp.de
Created on: 25.10.21
"""
from django.utils.translation import gettext_lazy as _, pgettext_lazy as _con
from konova.utils.quality import AbstractQualityChecker
class CompensationQualityChecker(AbstractQualityChecker):
def run_check(self):
""" Perform all defined data checks
Returns:
"""
self._check_states()
self._check_actions()
self._check_geometry()
self.valid = len(self.messages) == 0
def _check_states(self):
""" Checks data quality for related CompensationState objects
Returns:
"""
after_states = self.obj.get_surface_after_states()
before_states = self.obj.get_surface_before_states()
if after_states != before_states:
self.messages.append(
_("States unequal")
)
if before_states == 0:
self._add_missing_attr_name(_("States before"))
if after_states == 0:
self._add_missing_attr_name(_("States after"))
def _check_actions(self):
""" Checks data quality for related CompensationState objects
Returns:
"""
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 Legal
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"))