#26 Annual conservation report

* WIP: EcoAccountReport
pull/33/head
mpeltriaux 3 years ago
parent 0e9a169d38
commit b90a07ca2a

@ -11,7 +11,7 @@
<div class="col-sm-12 col-md-12 col-lg-12">
{% include 'analysis/reports/includes/intervention/card_intervention.html' %}
{% include 'analysis/reports/includes/compensation/card_compensation.html' %}
{% include 'analysis/reports/includes/card_eco_account.html' %}
{% include 'analysis/reports/includes/eco_account/card_eco_account.html' %}
{% include 'analysis/reports/includes/old_intervention/card_old_interventions.html' %}
</div>
{% endblock %}

@ -0,0 +1,32 @@
{% load i18n fontawesome_5 ksp_filters %}
<h3>{% trans 'Amount' %}</h3>
<strong>
{% blocktrans %}
Checked = Has been checked by the registration office according to LKompVzVo
{% endblocktrans %}
<br>
{% blocktrans %}
Recorded = Has been checked and published by the conservation office
{% endblocktrans %}
</strong>
<div class="table-container">
<table class="table table-hover">
<thead>
<tr>
<th scope="col">{% trans 'Before' %} LKompVzVo</th>
<th scope="col">{% trans 'After' %} LKompVzVo</th>
<th scope="col">{% fa5_icon 'bookmark' %} {% trans 'Recorded' %}</th>
<th scope="col" class="w-25">{% trans 'Total' %}</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{report.eco_account_report.queryset_old.count|default_if_zero:"-"}}</td>
<td>{{report.eco_account_report.queryset.count|default_if_zero:"-"}}</td>
<td>{{report.eco_account_report.queryset_recorded.count|default_if_zero:"-"}}</td>
<td>{{report.eco_account_report.queryset_total.count|default_if_zero:"-"}}</td>
</tr>
</tbody>
</table>
</div>

@ -15,7 +15,9 @@
</div>
<div id="ecoAccountsBody" class="collapse" aria-labelledby="ecoAccounts">
<div class="card-body">
{% include 'form/table/generic_table_form_body.html' %}
{% include 'analysis/reports/includes/eco_account/amount.html' %}
<hr>
{% include 'analysis/reports/includes/eco_account/deductions.html' %}
</div>
</div>
</div>

@ -0,0 +1,23 @@
{% load i18n fontawesome_5 ksp_filters %}
<h3>{% trans 'Deductions' %}</h3>
<div class="table-container">
<table class="table table-hover">
<thead>
<tr>
<th scope="col">{% fa5_icon 'bookmark' %} {% trans 'Recorded' %}</th>
<th scope="col">{% fa5_icon 'bookmark' %} {% trans 'Recorded' %} {% trans 'Surface' %}</th>
<th scope="col" class="w-25">{% trans 'Total' %}</th>
<th scope="col" class="w-25">{% trans 'Total' %} {% trans 'Surface' %}</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{report.eco_account_report.queryset_deductions_recorded.count|default_if_zero:"-"}}</td>
<td>{{report.eco_account_report.recorded_deductions_sq_m|default_if_zero:"-"}}m²</td>
<td>{{report.eco_account_report.queryset_deductions_recorded.count|default_if_zero:"-"}}</td>
<td>{{report.eco_account_report.deductions_sq_m|default_if_zero:"-"}}m²</td>
</tr>
</tbody>
</table>
</div>

@ -5,13 +5,16 @@ Contact: michel.peltriaux@sgdnord.rlp.de
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
from analysis.settings import LKOMPVZVO_PUBLISH_DATE
from codelist.models import KonovaCode
from codelist.settings import CODELIST_LAW_ID
from compensation.models import Compensation, Payment, EcoAccountDeduction
from compensation.models import Compensation, Payment, EcoAccountDeduction, EcoAccount
from intervention.models import Intervention
from konova.models import Geometry
@ -217,7 +220,9 @@ class TimespanReport:
return Geometry.objects.filter(
id__in=ids
).annotate(
num=NumGeometries("geom")
geom_cast=Cast("geom", MultiPolygonField())
).annotate(
num=NumGeometries("geom_cast")
).aggregate(
num_geoms=Sum("num")
)["num_geoms"] or 0
@ -265,6 +270,61 @@ class TimespanReport:
intervention__checked__isnull=False,
)
class EcoAccountReport:
queryset = EcoAccount.objects.none()
queryset_recorded = EcoAccount.objects.none()
queryset_old = EcoAccount.objects.none()
queryset_deductions = EcoAccountDeduction.objects.none()
queryset_deductions_recorded = EcoAccountDeduction.objects.none()
queryset_has_deductions = EcoAccountDeduction.objects.none()
# Total size of deductions
deductions_sq_m = -1
recorded_deductions_sq_m = -1
def __init__(self, id: str):
# First fetch all eco account for this office
self.queryset_total = EcoAccount.objects.filter(
responsible__conservation_office__id=id,
deleted=None,
)
self.queryset_recorded = self.queryset_total.filter(
recorded__isnull=False
)
# Then fetch the old ones (pre-LKompVzVo)
self.queryset_old = self.queryset_total.filter(
recorded__timestamp__lte=LKOMPVZVO_PUBLISH_DATE,
)
# Then fetch the default queryset with the new ones (post-LKompVzVo)
self.queryset = self.queryset_total.filter(
recorded__timestamp__gte=LKOMPVZVO_PUBLISH_DATE,
)
# Fetch all related deductions
self.queryset_deductions = EcoAccountDeduction.objects.filter(
account__id__in=self.queryset.values_list("id")
)
# Fetch deductions for interventions which are already recorded
self.queryset_deductions_recorded = self.queryset_deductions.filter(
intervention__recorded__isnull=False
)
self._create_report()
def _create_report(self):
""" Creates all report information
Returns:
"""
self._evaluate_deductions()
def _evaluate_deductions(self):
self.deductions_sq_m = self.queryset_deductions.aggregate(
sum=Sum("surface")
)["sum"]
self.recorded_deductions_sq_m = self.queryset_deductions_recorded.aggregate(
sum=Sum("surface")
)["sum"]
class OldInterventionReport:
queryset = Compensation.objects.none()
queryset_checked = Compensation.objects.none()
@ -287,4 +347,5 @@ class TimespanReport:
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)

@ -1,14 +1,9 @@
from django.contrib.auth.decorators import login_required
from django.db.models import Count, Q, Sum
from django.http import HttpRequest
from django.shortcuts import render, get_object_or_404
from analysis.utils.report import TimespanReport
from codelist.models import KonovaCode
from codelist.settings import CODELIST_LAW_ID
from compensation.models import EcoAccount, Compensation
from ema.models import Ema
from intervention.models import Intervention
from konova.contexts import BaseContext
from konova.decorators import conservation_office_group_required

@ -312,4 +312,5 @@ class Geometry(BaseResource):
Outsourced geometry model so multiple versions of the same object can refer to the same geometry if it is not changed
"""
from konova.settings import DEFAULT_SRID
geom = MultiPolygonField(null=True, blank=True, srid=DEFAULT_SRID)
# Read more about geography=True here: https://docs.djangoproject.com/en/3.2/ref/contrib/gis/model-api/#geography
geom = MultiPolygonField(null=True, blank=True, srid=DEFAULT_SRID, geography=True)

Binary file not shown.

@ -19,7 +19,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-10-19 13:23+0200\n"
"POT-Creation-Date: 2021-10-19 16:04+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -37,20 +37,10 @@ msgstr ""
msgid "Report"
msgstr "Bericht"
#: analysis/templates/analysis/reports/includes/card_eco_account.html:11
msgid "Eco-Accounts"
msgstr "Ökokonten"
#: analysis/templates/analysis/reports/includes/card_old_interventions.html:11
msgid "Old interventions"
msgstr "Altfälle"
#: analysis/templates/analysis/reports/includes/card_old_interventions.html:13
msgid "Before"
msgstr "Vor"
#: analysis/templates/analysis/reports/includes/compensation/amount.html:3
#: analysis/templates/analysis/reports/includes/eco_account/amount.html:3
#: analysis/templates/analysis/reports/includes/intervention/amount.html:3
#: analysis/templates/analysis/reports/includes/old_intervention/amount.html:3
#: compensation/forms/modalForms.py:351
#: compensation/templates/compensation/detail/eco_account/includes/deductions.html:34
#: intervention/templates/intervention/detail/includes/deductions.html:31
@ -58,7 +48,9 @@ msgid "Amount"
msgstr "Menge"
#: analysis/templates/analysis/reports/includes/compensation/amount.html:5
#: analysis/templates/analysis/reports/includes/eco_account/amount.html:5
#: analysis/templates/analysis/reports/includes/intervention/amount.html:5
#: analysis/templates/analysis/reports/includes/old_intervention/amount.html:5
msgid ""
"\n"
" Checked = Has been checked by the registration office according to "
@ -70,7 +62,9 @@ msgstr ""
" "
#: analysis/templates/analysis/reports/includes/compensation/amount.html:9
#: analysis/templates/analysis/reports/includes/eco_account/amount.html:9
#: analysis/templates/analysis/reports/includes/intervention/amount.html:9
#: analysis/templates/analysis/reports/includes/old_intervention/amount.html:9
msgid ""
"\n"
" Recorded = Has been checked and published by the conservation office\n"
@ -86,17 +80,25 @@ msgid "Area of responsibility"
msgstr "Zuständigkeitsbereich"
#: analysis/templates/analysis/reports/includes/compensation/amount.html:18
#: analysis/templates/analysis/reports/includes/compensation/card_compensation.html:11
#: compensation/tables.py:62
#: intervention/templates/intervention/detail/includes/compensations.html:8
#: intervention/templates/intervention/report/report.html:49
msgid "Compensations"
msgstr "Kompensationen"
#: analysis/templates/analysis/reports/includes/intervention/amount.html:17
#: analysis/templates/analysis/reports/includes/intervention/compensated_by.html:8
#: analysis/templates/analysis/reports/includes/intervention/laws.html:17
#: analysis/templates/analysis/reports/includes/old_intervention/amount.html:17
#: compensation/tables.py:35
#: compensation/templates/compensation/detail/compensation/view.html:43
#: intervention/tables.py:33
#: intervention/templates/intervention/detail/view.html:68 user/models.py:48
msgid "Checked"
msgstr "Geprüft"
#: analysis/templates/analysis/reports/includes/compensation/amount.html:19
#: analysis/templates/analysis/reports/includes/intervention/amount.html:19
#: analysis/templates/analysis/reports/includes/intervention/compensated_by.html:10
#: analysis/templates/analysis/reports/includes/eco_account/amount.html:19
#: analysis/templates/analysis/reports/includes/eco_account/deductions.html:8
#: analysis/templates/analysis/reports/includes/eco_account/deductions.html:9
#: analysis/templates/analysis/reports/includes/intervention/amount.html:18
#: analysis/templates/analysis/reports/includes/intervention/compensated_by.html:9
#: analysis/templates/analysis/reports/includes/intervention/laws.html:20
#: analysis/templates/analysis/reports/includes/old_intervention/amount.html:18
#: compensation/tables.py:41 compensation/tables.py:181
#: compensation/templates/compensation/detail/compensation/view.html:57
#: compensation/templates/compensation/detail/eco_account/includes/deductions.html:31
@ -111,37 +113,70 @@ msgstr "Verzeichnet"
msgid "Number single areas"
msgstr "Einzelflächen"
#: analysis/templates/analysis/reports/includes/compensation/amount.html:25
#: analysis/templates/analysis/reports/includes/compensation/amount.html:21
#: analysis/templates/analysis/reports/includes/compensation/amount.html:47
#: analysis/templates/analysis/reports/includes/eco_account/amount.html:20
#: analysis/templates/analysis/reports/includes/eco_account/deductions.html:10
#: analysis/templates/analysis/reports/includes/eco_account/deductions.html:11
#: analysis/templates/analysis/reports/includes/intervention/amount.html:19
#: analysis/templates/analysis/reports/includes/intervention/compensated_by.html:10
#: analysis/templates/analysis/reports/includes/intervention/laws.html:23
#: analysis/templates/analysis/reports/includes/intervention/laws.html:43
#: analysis/templates/analysis/reports/includes/old_intervention/amount.html:19
#: konova/templates/konova/home.html:23 konova/templates/konova/home.html:61
#: konova/templates/konova/home.html:100
msgid "Total"
msgstr "Insgesamt"
#: analysis/templates/analysis/reports/includes/compensation/amount.html:26
msgid "Conservation office by law"
msgstr "Naturschutzbehörde (§17 Abs.3 BNatSchG)"
#: analysis/templates/analysis/reports/includes/compensation/amount.html:31
#: analysis/templates/analysis/reports/includes/compensation/amount.html:33
msgid "Land-use planning"
msgstr "Träger Bauleitplanung"
#: analysis/templates/analysis/reports/includes/compensation/amount.html:40
msgid "Other registration office"
msgstr "Andere Zulassungsbehörden"
#: analysis/templates/analysis/reports/includes/compensation/amount.html:37
msgid "Land-use planning"
msgstr "Träger Bauleitplanung"
#: analysis/templates/analysis/reports/includes/compensation/card_compensation.html:11
#: compensation/tables.py:62
#: intervention/templates/intervention/detail/includes/compensations.html:8
#: intervention/templates/intervention/report/report.html:49
msgid "Compensations"
msgstr "Kompensationen"
#: analysis/templates/analysis/reports/includes/compensation/amount.html:43
#: analysis/templates/analysis/reports/includes/intervention/amount.html:17
#: analysis/templates/analysis/reports/includes/intervention/compensated_by.html:8
#: analysis/templates/analysis/reports/includes/intervention/laws.html:23
#: analysis/templates/analysis/reports/includes/intervention/laws.html:43
#: konova/templates/konova/home.html:23 konova/templates/konova/home.html:61
#: konova/templates/konova/home.html:100
msgid "Total"
msgstr "Insgesamt"
#: analysis/templates/analysis/reports/includes/eco_account/amount.html:17
#: analysis/templates/analysis/reports/includes/old_intervention/card_old_interventions.html:13
msgid "Before"
msgstr "Vor"
#: analysis/templates/analysis/reports/includes/intervention/amount.html:18
#: analysis/templates/analysis/reports/includes/intervention/compensated_by.html:9
#: analysis/templates/analysis/reports/includes/intervention/laws.html:17
#: compensation/tables.py:35
#: compensation/templates/compensation/detail/compensation/view.html:43
#: intervention/tables.py:33
#: intervention/templates/intervention/detail/view.html:68 user/models.py:48
msgid "Checked"
msgstr "Geprüft"
#: analysis/templates/analysis/reports/includes/eco_account/amount.html:18
msgid "After"
msgstr "Nach"
#: analysis/templates/analysis/reports/includes/eco_account/card_eco_account.html:11
msgid "Eco-Accounts"
msgstr "Ökokonten"
#: analysis/templates/analysis/reports/includes/eco_account/deductions.html:3
#: analysis/templates/analysis/reports/includes/intervention/compensated_by.html:27
msgid "Deductions"
msgstr "Abbuchungen"
#: analysis/templates/analysis/reports/includes/eco_account/deductions.html:9
#: analysis/templates/analysis/reports/includes/eco_account/deductions.html:11
#: compensation/forms/modalForms.py:152
#: compensation/templates/compensation/detail/compensation/includes/states-after.html:36
#: compensation/templates/compensation/detail/compensation/includes/states-before.html:36
#: compensation/templates/compensation/detail/eco_account/includes/states-after.html:36
#: compensation/templates/compensation/detail/eco_account/includes/states-before.html:36
#: ema/templates/ema/detail/includes/states-after.html:36
#: ema/templates/ema/detail/includes/states-before.html:36
#: intervention/forms/modalForms.py:274
msgid "Surface"
msgstr "Fläche"
#: analysis/templates/analysis/reports/includes/intervention/card_intervention.html:10
#: intervention/tables.py:66
@ -168,10 +203,6 @@ msgstr "Kompensation"
msgid "Payment"
msgstr "Zahlung"
#: analysis/templates/analysis/reports/includes/intervention/compensated_by.html:27
msgid "Deductions"
msgstr "Abbuchungen"
#: analysis/templates/analysis/reports/includes/intervention/laws.html:2
msgid "Law usage"
msgstr "Gesetzesanwendungen"
@ -197,6 +228,10 @@ msgstr ""
msgid "Law"
msgstr "Gesetz"
#: analysis/templates/analysis/reports/includes/old_intervention/card_old_interventions.html:11
msgid "Old interventions"
msgstr "Altfälle"
#: analysis/templates/analysis/reports/index.html:6
#: templates/navbars/navbar.html:46
msgid "Reports"
@ -400,17 +435,6 @@ msgstr "Biotoptyp"
msgid "Select the biotope type"
msgstr "Biotoptyp wählen"
#: compensation/forms/modalForms.py:152
#: compensation/templates/compensation/detail/compensation/includes/states-after.html:36
#: compensation/templates/compensation/detail/compensation/includes/states-before.html:36
#: compensation/templates/compensation/detail/eco_account/includes/states-after.html:36
#: compensation/templates/compensation/detail/eco_account/includes/states-before.html:36
#: ema/templates/ema/detail/includes/states-after.html:36
#: ema/templates/ema/detail/includes/states-before.html:36
#: intervention/forms/modalForms.py:274
msgid "Surface"
msgstr "Fläche"
#: compensation/forms/modalForms.py:155 intervention/forms/modalForms.py:276
msgid "in m²"
msgstr ""

Loading…
Cancel
Save