mpeltriaux
bcffae4a95
* renames model ResponsibilityData into Responsibility * renames model LegalData into Legal * moves form->object saving logic into model * refactors NewDocumentForm into special types for intervention, compensation, eco account and ema *
100 lines
3.1 KiB
Python
100 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 _
|
|
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):
|
|
""" Checks data quality of related Responsibility
|
|
|
|
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):
|
|
""" Checks data quality of related Legal
|
|
|
|
Args:
|
|
self.messages (dict): Holds error messages
|
|
|
|
Returns:
|
|
|
|
"""
|
|
try:
|
|
legal = self.obj.legal
|
|
# Check for a revocation
|
|
if legal.revocations.exists():
|
|
self.messages.append(_("Revocations exists"))
|
|
|
|
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:
|
|
|
|
"""
|
|
c_comps = self.obj.compensations.count()
|
|
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)")
|
|
)
|