#26 Annual conservation report

* enhancements for report2excel functionality
* improvements for report2html layout
+
This commit is contained in:
mpeltriaux 2021-10-22 12:36:39 +02:00
parent 9c523a0a0c
commit c7b22592de
9 changed files with 158 additions and 106 deletions

View File

@ -31,6 +31,6 @@
{% include 'analysis/reports/includes/intervention/card_intervention.html' %} {% include 'analysis/reports/includes/intervention/card_intervention.html' %}
{% include 'analysis/reports/includes/compensation/card_compensation.html' %} {% include 'analysis/reports/includes/compensation/card_compensation.html' %}
{% include 'analysis/reports/includes/eco_account/card_eco_account.html' %} {% include 'analysis/reports/includes/eco_account/card_eco_account.html' %}
{% include 'analysis/reports/includes/old_intervention/card_old_interventions.html' %} {% include 'analysis/reports/includes/old_data/card_old_interventions.html' %}
</div> </div>
{% endblock %} {% endblock %}

View File

@ -2,10 +2,6 @@
<h3>{% trans 'Amount' %}</h3> <h3>{% trans 'Amount' %}</h3>
<strong> <strong>
{% blocktrans %}
Checked = Has been checked by the registration office according to LKompVzVo
{% endblocktrans %}
<br>
{% blocktrans %} {% blocktrans %}
Recorded = Has been checked and published by the conservation office Recorded = Has been checked and published by the conservation office
{% endblocktrans %} {% endblocktrans %}
@ -14,18 +10,14 @@
<table class="table table-hover"> <table class="table table-hover">
<thead> <thead>
<tr> <tr>
<th scope="col">{% trans 'Before' %} LKompVzVo</th> <th scope="col" class="w-25">{% fa5_icon 'bookmark' %} {% trans 'Recorded' %}</th>
<th scope="col">{% trans 'After' %} LKompVzVo</th> <th scope="col">{% trans 'Total' %}</th>
<th scope="col">{% fa5_icon 'bookmark' %} {% trans 'Recorded' %}</th>
<th scope="col" class="w-25">{% trans 'Total' %}</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr> <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_recorded_count|default_if_zero:"-"}}</td>
<td>{{report.eco_account_report.queryset_total_count|default_if_zero:"-"}}</td> <td>{{report.eco_account_report.queryset_count|default_if_zero:"-"}}</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>

View File

@ -0,0 +1,40 @@
{% 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" class="w-25">{% fa5_icon 'star' %} {% trans 'Type' %}</th>
<th scope="col">{% fa5_icon 'bookmark' %} {% trans 'Recorded' %}</th>
<th scope="col">{% trans 'Total' %}</th>
</tr>
</thead>
<tbody>
<tr>
<td>{% trans 'Intervention' %}</td>
<td>{{report.old_data_report.queryset_intervention_recorded_count|default_if_zero:"-"}}</td>
<td>{{report.old_data_report.queryset_intervention_count|default_if_zero:"-"}}</td>
</tr>
<tr>
<td>{% trans 'Compensation' %}</td>
<td>{{report.old_data_report.queryset_comps_recorded_count|default_if_zero:"-"}}</td>
<td>{{report.old_data_report.queryset_comps_count|default_if_zero:"-"}}</td>
</tr>
<tr>
<td>{% trans 'Eco-account' %}</td>
<td>{{report.old_data_report.queryset_acc_recorded_count|default_if_zero:"-"}}</td>
<td>{{report.old_data_report.queryset_acc_count|default_if_zero:"-"}}</td>
</tr>
</tbody>
</table>
</div>

View File

@ -16,7 +16,7 @@
</div> </div>
<div id="oldInterventionBody" class="collapse" aria-labelledby="oldIntervention"> <div id="oldInterventionBody" class="collapse" aria-labelledby="oldIntervention">
<div class="card-body"> <div class="card-body">
{% include 'analysis/reports/includes/old_intervention/amount.html' %} {% include 'analysis/reports/includes/old_data/amount.html' %}
</div> </div>
</div> </div>
</div> </div>

View File

@ -1,30 +0,0 @@
{% 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">{% fa5_icon 'star' %} {% trans 'Checked' %}</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.old_intervention_report.queryset_checked_count|default_if_zero:"-"}}</td>
<td>{{report.old_intervention_report.queryset_recorded_count|default_if_zero:"-"}}</td>
<td>{{report.old_intervention_report.queryset_count|default_if_zero:"-"}}</td>
</tr>
</tbody>
</table>
</div>

View File

@ -47,28 +47,30 @@ class TempExcelFile:
Returns: Returns:
""" """
ws = self._workbook.active sheets = self._workbook.worksheets
# Always activate sheet protection for sheet in sheets:
ws.protection.sheet = True ws = sheet
ws.protection.enable() # Always activate sheet protection
_rows = ws.iter_rows(start_row) ws.protection.sheet = True
for row in _rows: ws.protection.enable()
for cell in row: _rows = ws.iter_rows(start_row)
val = cell.value for row in _rows:
if val in self._template_map: for cell in row:
attr = self._template_map[val] val = cell.value
# If keyword '_iter' can be found inside the placeholder value it's an iterable and we if val in self._template_map:
# need to process it differently attr = self._template_map[val]
if isinstance(attr, dict): # If keyword '_iter' can be found inside the placeholder value it's an iterable and we
# Read the iterable object and related attributes from the dict # need to process it differently
_iter_obj = attr.get("iterable", None) if isinstance(attr, dict):
_attrs = attr.get("attrs", []) # Read the iterable object and related attributes from the dict
self._add_cells_from_iterable(ws, cell, _iter_obj, _attrs) _iter_obj = attr.get("iterable", None)
# Since the sheet length did change now, we need to rerun this function starting with the new _attrs = attr.get("attrs", [])
# row counter self._add_cells_from_iterable(ws, cell, _iter_obj, _attrs)
self._replace_template_placeholders(start_row=cell.row + len(_iter_obj)) # Since the sheet length did change now, we need to rerun this function starting with the new
else: # row counter
cell.value = attr self._replace_template_placeholders(start_row=cell.row + len(_iter_obj))
else:
cell.value = attr
self._workbook.save(self._file.name) self._workbook.save(self._file.name)
self._file.seek(0) self._file.seek(0)
self.stream = self._file.read() self.stream = self._file.read()

View File

@ -379,14 +379,10 @@ class TimespanReport:
self.queryset_registration_office_other_recorded_count = self.queryset_registration_office_other_recorded.count() self.queryset_registration_office_other_recorded_count = self.queryset_registration_office_other_recorded.count()
class EcoAccountReport: class EcoAccountReport:
queryset_total = EcoAccount.objects.none()
queryset = EcoAccount.objects.none() queryset = EcoAccount.objects.none()
queryset_recorded = EcoAccount.objects.none() queryset_recorded = EcoAccount.objects.none()
queryset_old = EcoAccount.objects.none()
queryset_total_count = -1
queryset_count = -1 queryset_count = -1
queryset_recorded_count = -1 queryset_recorded_count = -1
queryset_old_count = -1
queryset_deductions = EcoAccountDeduction.objects.none() queryset_deductions = EcoAccountDeduction.objects.none()
queryset_deductions_recorded = EcoAccountDeduction.objects.none() queryset_deductions_recorded = EcoAccountDeduction.objects.none()
@ -401,23 +397,15 @@ class TimespanReport:
def __init__(self, id: str, date_from: str, date_to: str): def __init__(self, id: str, date_from: str, date_to: str):
# First fetch all eco account for this office # First fetch all eco account for this office
self.queryset_total = EcoAccount.objects.filter( self.queryset = EcoAccount.objects.filter(
responsible__conservation_office__id=id, responsible__conservation_office__id=id,
deleted=None, deleted=None,
created__timestamp__gte=date_from, created__timestamp__gte=date_from,
created__timestamp__lte=date_to, created__timestamp__lte=date_to,
) )
self.queryset_recorded = self.queryset_total.filter( self.queryset_recorded = self.queryset.filter(
recorded__isnull=False 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 # Fetch all related deductions
self.queryset_deductions = EcoAccountDeduction.objects.filter( self.queryset_deductions = EcoAccountDeduction.objects.filter(
account__id__in=self.queryset.values_list("id") account__id__in=self.queryset.values_list("id")
@ -427,15 +415,29 @@ class TimespanReport:
intervention__recorded__isnull=False intervention__recorded__isnull=False
) )
self.queryset_total_count = self.queryset_total.count()
self.queryset_count = self.queryset.count() self.queryset_count = self.queryset.count()
self.queryset_old_count = self.queryset_old.count() self.queryset_recorded_count = self.queryset_recorded.count()
self.queryset_recorded = self.queryset_recorded.count()
self.queryset_deductions_count = self.queryset_deductions.count() self.queryset_deductions_count = self.queryset_deductions.count()
self.queryset_deductions_recorded_count = self.queryset_deductions_recorded.count() self.queryset_deductions_recorded_count = self.queryset_deductions_recorded.count()
self.queryset_has_deductions_count = self.queryset_has_deductions.count() self.queryset_has_deductions_count = self.queryset_has_deductions.count()
self._create_report() self._create_report()
self._define_excel_map()
def _define_excel_map(self):
""" Define the excel map, which holds values for each placeholder used in the template
Returns:
"""
self.excel_map = {
"acc_total": self.queryset_count,
"acc_recorded": self.queryset_recorded_count,
"acc_deduc_recorded": self.queryset_deductions_recorded_count,
"acc_deduc_surface_recorded": self.recorded_deductions_sq_m,
"acc_deduc_total": self.queryset_deductions_count,
"acc_deduc_surface_total": self.deductions_sq_m,
}
def _create_report(self): def _create_report(self):
""" Creates all report information """ Creates all report information
@ -453,32 +455,76 @@ class TimespanReport:
sum=Sum("surface") sum=Sum("surface")
)["sum"] or 0 )["sum"] or 0
class OldInterventionReport: class OldDataReport:
queryset = Compensation.objects.none() """
queryset_checked = Compensation.objects.none() Evaluates 'old data' (registered (zugelassen) before 16.06.2018)
queryset_recorded = Compensation.objects.none() """
queryset_intervention = Intervention.objects.none()
queryset_intervention_recorded = Intervention.objects.none()
queryset_intervention_count = -1
queryset_intervention_recorded_count = -1
queryset_count = -1 queryset_comps = Compensation.objects.none()
queryset_checked_count = -1 queryset_comps_recorded = Compensation.objects.none()
queryset_recorded_count = -1 queryset_comps_count = -1
queryset_comps_recorded_count = -1
queryset_acc = EcoAccount.objects.none()
queryset_acc_recorded = EcoAccount.objects.none()
queryset_acc_count = -1
queryset_acc_recorded_count = -1
def __init__(self, id: str, date_from: str, date_to: str): def __init__(self, id: str, date_from: str, date_to: str):
self.queryset = Intervention.objects.filter( self.queryset_intervention = Intervention.objects.filter(
legal__registration_date__lte=LKOMPVZVO_PUBLISH_DATE, legal__registration_date__lte=LKOMPVZVO_PUBLISH_DATE,
responsible__conservation_office__id=id, responsible__conservation_office__id=id,
deleted=None, deleted=None,
created__timestamp__gte=date_from, created__timestamp__gte=date_from,
created__timestamp__lte=date_to, created__timestamp__lte=date_to,
) )
self.queryset_checked = self.queryset.filter( self.queryset_intervention_recorded = self.queryset_intervention.filter(
checked__isnull=False
)
self.queryset_recorded = self.queryset.filter(
recorded__isnull=False recorded__isnull=False
) )
self.queryset_count = self.queryset.count() self.queryset_intervention_count = self.queryset_intervention.count()
self.queryset_checked = self.queryset_checked.count() self.queryset_intervention_recorded_count = self.queryset_intervention_recorded.count()
self.queryset_recorded = self.queryset_recorded.count()
self.queryset_comps = Compensation.objects.filter(
intervention__in=self.queryset_intervention
)
self.queryset_comps_recorded = Compensation.objects.filter(
intervention__in=self.queryset_intervention_recorded,
)
self.queryset_comps_count = self.queryset_comps.count()
self.queryset_comps_recorded_count = self.queryset_comps_recorded.count()
self.queryset_acc = EcoAccount.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_acc_recorded = self.queryset_acc.filter(
recorded__isnull=False,
)
self.queryset_acc_count = self.queryset_acc.count()
self.queryset_acc_recorded_count = self.queryset_acc_recorded.count()
self._define_excel_map()
def _define_excel_map(self):
""" Define the excel map, which holds values for each placeholder used in the template
Returns:
"""
self.excel_map = {
"old_i_recorded": self.queryset_intervention_recorded_count,
"old_i_total": self.queryset_intervention_count,
"old_c_recorded": self.queryset_comps_recorded_count,
"old_c_total": self.queryset_comps_count,
"old_ea_recorded": self.queryset_acc_recorded_count,
"old_ea_total": self.queryset_acc_count,
}
def __init__(self, office_id: str, date_from: str, date_to: str): def __init__(self, office_id: str, date_from: str, date_to: str):
self.office_id = office_id self.office_id = office_id
@ -488,7 +534,7 @@ class TimespanReport:
self.intervention_report = self.InterventionReport(self.office_id, date_from, 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.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.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) self.old_data_report = self.OldDataReport(self.office_id, date_from, date_to)
# Build excel map # Build excel map
self.excel_map = { self.excel_map = {
@ -497,3 +543,5 @@ class TimespanReport:
} }
self.excel_map.update(self.intervention_report.excel_map) self.excel_map.update(self.intervention_report.excel_map)
self.excel_map.update(self.compensation_report.excel_map) self.excel_map.update(self.compensation_report.excel_map)
self.excel_map.update(self.eco_account_report.excel_map)
self.excel_map.update(self.old_data_report.excel_map)

View File

@ -77,7 +77,7 @@ msgstr "bis"
#: analysis/templates/analysis/reports/includes/compensation/amount.html:3 #: analysis/templates/analysis/reports/includes/compensation/amount.html:3
#: analysis/templates/analysis/reports/includes/eco_account/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/intervention/amount.html:3
#: analysis/templates/analysis/reports/includes/old_intervention/amount.html:3 #: analysis/templates/analysis/reports/includes/old_data/amount.html:3
#: compensation/forms/modalForms.py:351 #: compensation/forms/modalForms.py:351
#: compensation/templates/compensation/detail/eco_account/includes/deductions.html:34 #: compensation/templates/compensation/detail/eco_account/includes/deductions.html:34
#: intervention/templates/intervention/detail/includes/deductions.html:31 #: intervention/templates/intervention/detail/includes/deductions.html:31
@ -87,7 +87,7 @@ msgstr "Menge"
#: analysis/templates/analysis/reports/includes/compensation/amount.html:5 #: analysis/templates/analysis/reports/includes/compensation/amount.html:5
#: analysis/templates/analysis/reports/includes/eco_account/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/intervention/amount.html:5
#: analysis/templates/analysis/reports/includes/old_intervention/amount.html:5 #: analysis/templates/analysis/reports/includes/old_data/amount.html:5
msgid "" msgid ""
"\n" "\n"
" Checked = Has been checked by the registration office according to " " Checked = Has been checked by the registration office according to "
@ -101,7 +101,7 @@ msgstr ""
#: analysis/templates/analysis/reports/includes/compensation/amount.html:9 #: analysis/templates/analysis/reports/includes/compensation/amount.html:9
#: analysis/templates/analysis/reports/includes/eco_account/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/intervention/amount.html:9
#: analysis/templates/analysis/reports/includes/old_intervention/amount.html:9 #: analysis/templates/analysis/reports/includes/old_data/amount.html:9
msgid "" msgid ""
"\n" "\n"
" Recorded = Has been checked and published by the conservation office\n" " Recorded = Has been checked and published by the conservation office\n"
@ -120,7 +120,7 @@ msgstr "Zuständigkeitsbereich"
#: analysis/templates/analysis/reports/includes/intervention/amount.html:17 #: 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/compensated_by.html:8
#: analysis/templates/analysis/reports/includes/intervention/laws.html:17 #: analysis/templates/analysis/reports/includes/intervention/laws.html:17
#: analysis/templates/analysis/reports/includes/old_intervention/amount.html:17 #: analysis/templates/analysis/reports/includes/old_data/amount.html:17
#: compensation/tables.py:35 #: compensation/tables.py:35
#: compensation/templates/compensation/detail/compensation/view.html:43 #: compensation/templates/compensation/detail/compensation/view.html:43
#: intervention/tables.py:33 #: intervention/tables.py:33
@ -135,7 +135,7 @@ msgstr "Geprüft"
#: analysis/templates/analysis/reports/includes/intervention/amount.html:18 #: 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/compensated_by.html:9
#: analysis/templates/analysis/reports/includes/intervention/laws.html:20 #: analysis/templates/analysis/reports/includes/intervention/laws.html:20
#: analysis/templates/analysis/reports/includes/old_intervention/amount.html:18 #: analysis/templates/analysis/reports/includes/old_data/amount.html:18
#: compensation/tables.py:41 compensation/tables.py:181 #: compensation/tables.py:41 compensation/tables.py:181
#: compensation/templates/compensation/detail/compensation/view.html:57 #: compensation/templates/compensation/detail/compensation/view.html:57
#: compensation/templates/compensation/detail/eco_account/includes/deductions.html:31 #: compensation/templates/compensation/detail/eco_account/includes/deductions.html:31
@ -159,7 +159,7 @@ msgstr "Einzelflächen"
#: analysis/templates/analysis/reports/includes/intervention/compensated_by.html:10 #: 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:23
#: analysis/templates/analysis/reports/includes/intervention/laws.html:43 #: analysis/templates/analysis/reports/includes/intervention/laws.html:43
#: analysis/templates/analysis/reports/includes/old_intervention/amount.html:19 #: analysis/templates/analysis/reports/includes/old_data/amount.html:19
#: konova/templates/konova/home.html:23 konova/templates/konova/home.html:61 #: konova/templates/konova/home.html:23 konova/templates/konova/home.html:61
#: konova/templates/konova/home.html:100 #: konova/templates/konova/home.html:100
msgid "Total" msgid "Total"
@ -185,7 +185,7 @@ msgid "Compensations"
msgstr "Kompensationen" msgstr "Kompensationen"
#: analysis/templates/analysis/reports/includes/eco_account/amount.html:17 #: analysis/templates/analysis/reports/includes/eco_account/amount.html:17
#: analysis/templates/analysis/reports/includes/old_intervention/card_old_interventions.html:13 #: analysis/templates/analysis/reports/includes/old_data/card_old_interventions.html:13
msgid "Before" msgid "Before"
msgstr "Vor" msgstr "Vor"
@ -265,7 +265,7 @@ msgstr ""
msgid "Law" msgid "Law"
msgstr "Gesetz" msgstr "Gesetz"
#: analysis/templates/analysis/reports/includes/old_intervention/card_old_interventions.html:11 #: analysis/templates/analysis/reports/includes/old_data/card_old_interventions.html:11
msgid "Old interventions" msgid "Old interventions"
msgstr "Altfälle" msgstr "Altfälle"