#26 Annual conservation reports
* adds index form for selecting timespan and office of interest * adds timespan support for TimespanReport * fixes naive datetime issues * fixes missing error message css tag * adds/updates translations
This commit is contained in:
@@ -7,7 +7,6 @@ Created on: 18.10.21
|
||||
"""
|
||||
from django.contrib.gis.db.models import MultiPolygonField
|
||||
from django.contrib.gis.db.models.functions import NumGeometries
|
||||
from django.contrib.gis.measure import Area
|
||||
from django.db.models import Count, Sum, Q
|
||||
from django.db.models.functions import Cast
|
||||
|
||||
@@ -20,14 +19,18 @@ from konova.models import Geometry
|
||||
|
||||
|
||||
class TimespanReport:
|
||||
""" Holds multiple report elements for a timespan report
|
||||
|
||||
"""
|
||||
office_id = -1
|
||||
date_from = -1
|
||||
date_to = -1
|
||||
|
||||
class InterventionReport:
|
||||
queryset = Intervention.objects.none()
|
||||
queryset_checked = Intervention.objects.none()
|
||||
queryset_recorded = Intervention.objects.none()
|
||||
|
||||
|
||||
# Law related
|
||||
law_sum = -1
|
||||
law_sum_checked = -1
|
||||
@@ -45,11 +48,13 @@ class TimespanReport:
|
||||
deduction_sum_checked = -1
|
||||
deduction_sum_recorded = -1
|
||||
|
||||
def __init__(self, id: str):
|
||||
def __init__(self, id: str, date_from: str, date_to: str):
|
||||
self.queryset = Intervention.objects.filter(
|
||||
responsible__conservation_office__id=id,
|
||||
legal__registration_date__gt=LKOMPVZVO_PUBLISH_DATE,
|
||||
deleted=None,
|
||||
created__timestamp__gte=date_from,
|
||||
created__timestamp__lte=date_to,
|
||||
)
|
||||
self.queryset_checked = self.queryset.filter(
|
||||
checked__isnull=False
|
||||
@@ -160,11 +165,13 @@ class TimespanReport:
|
||||
# Code list id for 'obere Naturschutzbehörde'
|
||||
id_onb = 1943084
|
||||
|
||||
def __init__(self, id: str):
|
||||
def __init__(self, id: str, date_from: str, date_to: str):
|
||||
self.queryset = Compensation.objects.filter(
|
||||
intervention__responsible__conservation_office__id=id,
|
||||
intervention__legal__registration_date__gt=LKOMPVZVO_PUBLISH_DATE,
|
||||
deleted=None,
|
||||
intervention__created__timestamp__gte=date_from,
|
||||
intervention__created__timestamp__lte=date_to,
|
||||
)
|
||||
self.queryset_checked = self.queryset.filter(
|
||||
intervention__checked__isnull=False
|
||||
@@ -282,11 +289,13 @@ class TimespanReport:
|
||||
deductions_sq_m = -1
|
||||
recorded_deductions_sq_m = -1
|
||||
|
||||
def __init__(self, id: str):
|
||||
def __init__(self, id: str, date_from: str, date_to: str):
|
||||
# First fetch all eco account for this office
|
||||
self.queryset_total = EcoAccount.objects.filter(
|
||||
responsible__conservation_office__id=id,
|
||||
deleted=None,
|
||||
created__timestamp__gte=date_from,
|
||||
created__timestamp__lte=date_to,
|
||||
)
|
||||
self.queryset_recorded = self.queryset_total.filter(
|
||||
recorded__isnull=False
|
||||
@@ -320,21 +329,23 @@ class TimespanReport:
|
||||
def _evaluate_deductions(self):
|
||||
self.deductions_sq_m = self.queryset_deductions.aggregate(
|
||||
sum=Sum("surface")
|
||||
)["sum"]
|
||||
)["sum"] or 0
|
||||
self.recorded_deductions_sq_m = self.queryset_deductions_recorded.aggregate(
|
||||
sum=Sum("surface")
|
||||
)["sum"]
|
||||
)["sum"] or 0
|
||||
|
||||
class OldInterventionReport:
|
||||
queryset = Compensation.objects.none()
|
||||
queryset_checked = Compensation.objects.none()
|
||||
queryset_recorded = Compensation.objects.none()
|
||||
|
||||
def __init__(self, id: str):
|
||||
def __init__(self, id: str, date_from: str, date_to: str):
|
||||
self.queryset = Intervention.objects.filter(
|
||||
legal__registration_date__lte=LKOMPVZVO_PUBLISH_DATE,
|
||||
responsible__conservation_office__id=id,
|
||||
deleted=None,
|
||||
created__timestamp__gte=date_from,
|
||||
created__timestamp__lte=date_to,
|
||||
)
|
||||
self.queryset_checked = self.queryset.filter(
|
||||
checked__isnull=False
|
||||
@@ -343,9 +354,12 @@ class TimespanReport:
|
||||
recorded__isnull=False
|
||||
)
|
||||
|
||||
def __init__(self, office_id: str):
|
||||
def __init__(self, office_id: str, date_from: str, date_to: str):
|
||||
self.office_id = office_id
|
||||
self.intervention_report = self.InterventionReport(self.office_id)
|
||||
self.compensation_report = self.CompensationReport(self.office_id)
|
||||
self.eco_account_report = self.EcoAccountReport(self.office_id)
|
||||
self.old_intervention_report = self.OldInterventionReport(self.office_id)
|
||||
self.date_from = date_from
|
||||
self.date_to = date_to
|
||||
|
||||
self.intervention_report = self.InterventionReport(self.office_id, date_from, date_to)
|
||||
self.compensation_report = self.CompensationReport(self.office_id, date_from, date_to)
|
||||
self.eco_account_report = self.EcoAccountReport(self.office_id, date_from, date_to)
|
||||
self.old_intervention_report = self.OldInterventionReport(self.office_id, date_from, date_to)
|
||||
|
||||
Reference in New Issue
Block a user