#36 Quality checks
* adds quality check logic for EcoAccount with EcoAccountQualityChecker * adds/updates translations * adds quality check logic for EMA with EmaQualityChecker
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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"))
|
||||
|
||||
Reference in New Issue
Block a user