diff --git a/analysis/templates/analysis/reports/detail.html b/analysis/templates/analysis/reports/detail.html index 4232241..4497adf 100644 --- a/analysis/templates/analysis/reports/detail.html +++ b/analysis/templates/analysis/reports/detail.html @@ -11,7 +11,7 @@
{% 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' %}
{% endblock %} \ No newline at end of file diff --git a/analysis/templates/analysis/reports/includes/eco_account/amount.html b/analysis/templates/analysis/reports/includes/eco_account/amount.html new file mode 100644 index 0000000..092ee9a --- /dev/null +++ b/analysis/templates/analysis/reports/includes/eco_account/amount.html @@ -0,0 +1,32 @@ +{% load i18n fontawesome_5 ksp_filters %} + +

{% trans 'Amount' %}

+ + {% blocktrans %} + Checked = Has been checked by the registration office according to LKompVzVo + {% endblocktrans %} +
+ {% blocktrans %} + Recorded = Has been checked and published by the conservation office + {% endblocktrans %} +
+
+ + + + + + + + + + + + + + + + + +
{% trans 'Before' %} LKompVzVo{% trans 'After' %} LKompVzVo{% fa5_icon 'bookmark' %} {% trans 'Recorded' %}{% trans 'Total' %}
{{report.eco_account_report.queryset_old.count|default_if_zero:"-"}}{{report.eco_account_report.queryset.count|default_if_zero:"-"}}{{report.eco_account_report.queryset_recorded.count|default_if_zero:"-"}}{{report.eco_account_report.queryset_total.count|default_if_zero:"-"}}
+
\ No newline at end of file diff --git a/analysis/templates/analysis/reports/includes/card_eco_account.html b/analysis/templates/analysis/reports/includes/eco_account/card_eco_account.html similarity index 79% rename from analysis/templates/analysis/reports/includes/card_eco_account.html rename to analysis/templates/analysis/reports/includes/eco_account/card_eco_account.html index 744ce07..850ac60 100644 --- a/analysis/templates/analysis/reports/includes/card_eco_account.html +++ b/analysis/templates/analysis/reports/includes/eco_account/card_eco_account.html @@ -15,7 +15,9 @@
- {% include 'form/table/generic_table_form_body.html' %} + {% include 'analysis/reports/includes/eco_account/amount.html' %} +
+ {% include 'analysis/reports/includes/eco_account/deductions.html' %}
diff --git a/analysis/templates/analysis/reports/includes/eco_account/deductions.html b/analysis/templates/analysis/reports/includes/eco_account/deductions.html new file mode 100644 index 0000000..1520e08 --- /dev/null +++ b/analysis/templates/analysis/reports/includes/eco_account/deductions.html @@ -0,0 +1,23 @@ +{% load i18n fontawesome_5 ksp_filters %} + +

{% trans 'Deductions' %}

+
+ + + + + + + + + + + + + + + + + +
{% fa5_icon 'bookmark' %} {% trans 'Recorded' %}{% fa5_icon 'bookmark' %} {% trans 'Recorded' %} {% trans 'Surface' %}{% trans 'Total' %}{% trans 'Total' %} {% trans 'Surface' %}
{{report.eco_account_report.queryset_deductions_recorded.count|default_if_zero:"-"}}{{report.eco_account_report.recorded_deductions_sq_m|default_if_zero:"-"}}m²{{report.eco_account_report.queryset_deductions_recorded.count|default_if_zero:"-"}}{{report.eco_account_report.deductions_sq_m|default_if_zero:"-"}}m²
+
\ No newline at end of file diff --git a/analysis/utils/report.py b/analysis/utils/report.py index 12d0a46..4792a16 100644 --- a/analysis/utils/report.py +++ b/analysis/utils/report.py @@ -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) diff --git a/analysis/views.py b/analysis/views.py index b769971..7e297e6 100644 --- a/analysis/views.py +++ b/analysis/views.py @@ -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 diff --git a/konova/models.py b/konova/models.py index f9f8758..2b351e1 100644 --- a/konova/models.py +++ b/konova/models.py @@ -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) diff --git a/locale/de/LC_MESSAGES/django.mo b/locale/de/LC_MESSAGES/django.mo index 1523b7a..5a1733c 100644 Binary files a/locale/de/LC_MESSAGES/django.mo and b/locale/de/LC_MESSAGES/django.mo differ diff --git a/locale/de/LC_MESSAGES/django.po b/locale/de/LC_MESSAGES/django.po index 17306e7..85533a6 100644 --- a/locale/de/LC_MESSAGES/django.po +++ b/locale/de/LC_MESSAGES/django.po @@ -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 \n" "Language-Team: LANGUAGE \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 ""