2021-10-25 13:06:54 +02:00
|
|
|
"""
|
|
|
|
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 _
|
|
|
|
from konova.utils.quality import AbstractQualityChecker
|
|
|
|
|
|
|
|
|
|
|
|
class InterventionQualityChecker(AbstractQualityChecker):
|
|
|
|
def run_check(self):
|
|
|
|
""" Perform all defined data checks
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
self._check_responsible_data()
|
|
|
|
self._check_legal_data()
|
|
|
|
self._check_compensations()
|
|
|
|
self._check_geometry()
|
|
|
|
self.valid = len(self.messages) == 0
|
|
|
|
|
|
|
|
def _check_responsible_data(self):
|
2021-11-15 17:09:17 +01:00
|
|
|
""" Checks data quality of related Responsibility
|
2021-10-25 13:06:54 +02:00
|
|
|
|
|
|
|
Args:
|
|
|
|
self.messages (dict): Holds error messages
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
resp = self.obj.responsible
|
|
|
|
# Check for file numbers
|
|
|
|
if not resp.registration_file_number or len(resp.registration_file_number) == 0:
|
|
|
|
self._add_missing_attr_name(_("Registration office file number"))
|
|
|
|
|
|
|
|
if not resp.conservation_file_number or len(resp.conservation_file_number) == 0:
|
|
|
|
self._add_missing_attr_name(_("Conservation office file number"))
|
|
|
|
|
|
|
|
# Check for selected offices
|
|
|
|
if resp.registration_office is None:
|
|
|
|
self._add_missing_attr_name(_("Registration office"))
|
|
|
|
|
|
|
|
if resp.conservation_office is None:
|
|
|
|
self._add_missing_attr_name(_("Conservation office"))
|
|
|
|
|
|
|
|
if resp.handler is None:
|
|
|
|
self._add_missing_attr_name(_("Intervention handler"))
|
|
|
|
except AttributeError:
|
|
|
|
# responsible data not found
|
|
|
|
self._add_missing_attr_name(_("Responsible data"))
|
|
|
|
|
|
|
|
def _check_legal_data(self):
|
2021-11-15 17:09:17 +01:00
|
|
|
""" Checks data quality of related Legal
|
2021-10-25 13:06:54 +02:00
|
|
|
|
|
|
|
Args:
|
|
|
|
self.messages (dict): Holds error messages
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
legal = self.obj.legal
|
|
|
|
# Check for a revocation
|
2021-11-15 12:18:22 +01:00
|
|
|
if legal.revocations.exists():
|
|
|
|
self.messages.append(_("Revocations exists"))
|
2021-10-25 13:06:54 +02:00
|
|
|
|
|
|
|
if legal.registration_date is None:
|
|
|
|
self._add_missing_attr_name(_("Registration date"))
|
|
|
|
|
|
|
|
if legal.binding_date is None:
|
|
|
|
self._add_missing_attr_name(_("Binding date"))
|
|
|
|
|
|
|
|
if legal.laws.count() == 0:
|
|
|
|
self._add_missing_attr_name(_("Laws"))
|
|
|
|
|
|
|
|
if legal.process_type is None:
|
|
|
|
self._add_missing_attr_name(_("Process type"))
|
|
|
|
except AttributeError:
|
|
|
|
self._add_missing_attr_name(_("Legal data"))
|
|
|
|
|
|
|
|
def _check_compensations(self):
|
|
|
|
""" Checks for compensation, deduction or payment
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
"""
|
2022-02-04 15:59:53 +01:00
|
|
|
comps = self.obj.compensations.filter(
|
|
|
|
deleted=None
|
|
|
|
)
|
|
|
|
c_comps = comps.count()
|
2021-10-25 13:06:54 +02:00
|
|
|
c_pays = self.obj.payments.count()
|
|
|
|
c_deducs = self.obj.deductions.count()
|
|
|
|
c_all = c_comps + c_pays + c_deducs
|
|
|
|
if c_all == 0:
|
|
|
|
self.messages.append(
|
|
|
|
_("No compensation of any type found (Compensation, Payment, Deduction)")
|
|
|
|
)
|