diff --git a/analysis/templates/analysis/reports/detail.html b/analysis/templates/analysis/reports/detail.html index 9cdae7d2..ac4f08e2 100644 --- a/analysis/templates/analysis/reports/detail.html +++ b/analysis/templates/analysis/reports/detail.html @@ -31,6 +31,6 @@ {% include 'analysis/reports/includes/intervention/card_intervention.html' %} {% include 'analysis/reports/includes/compensation/card_compensation.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' %} {% 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 index becdfff9..668250e6 100644 --- a/analysis/templates/analysis/reports/includes/eco_account/amount.html +++ b/analysis/templates/analysis/reports/includes/eco_account/amount.html @@ -2,10 +2,6 @@

{% 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 %} @@ -14,18 +10,14 @@ - - - - + + - - - +
{% trans 'Before' %} LKompVzVo{% trans 'After' %} LKompVzVo{% fa5_icon 'bookmark' %} {% trans 'Recorded' %}{% trans 'Total' %}{% 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:"-"}}{{report.eco_account_report.queryset_count|default_if_zero:"-"}}
diff --git a/analysis/templates/analysis/reports/includes/old_data/amount.html b/analysis/templates/analysis/reports/includes/old_data/amount.html new file mode 100644 index 00000000..cd79cb6f --- /dev/null +++ b/analysis/templates/analysis/reports/includes/old_data/amount.html @@ -0,0 +1,40 @@ +{% 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 %} +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + +
{% fa5_icon 'star' %} {% trans 'Type' %}{% fa5_icon 'bookmark' %} {% trans 'Recorded' %}{% trans 'Total' %}
{% trans 'Intervention' %}{{report.old_data_report.queryset_intervention_recorded_count|default_if_zero:"-"}}{{report.old_data_report.queryset_intervention_count|default_if_zero:"-"}}
{% trans 'Compensation' %}{{report.old_data_report.queryset_comps_recorded_count|default_if_zero:"-"}}{{report.old_data_report.queryset_comps_count|default_if_zero:"-"}}
{% trans 'Eco-account' %}{{report.old_data_report.queryset_acc_recorded_count|default_if_zero:"-"}}{{report.old_data_report.queryset_acc_count|default_if_zero:"-"}}
+
\ No newline at end of file diff --git a/analysis/templates/analysis/reports/includes/old_intervention/card_old_interventions.html b/analysis/templates/analysis/reports/includes/old_data/card_old_interventions.html similarity index 97% rename from analysis/templates/analysis/reports/includes/old_intervention/card_old_interventions.html rename to analysis/templates/analysis/reports/includes/old_data/card_old_interventions.html index 3a272874..a25a5712 100644 --- a/analysis/templates/analysis/reports/includes/old_intervention/card_old_interventions.html +++ b/analysis/templates/analysis/reports/includes/old_data/card_old_interventions.html @@ -16,7 +16,7 @@
- {% include 'analysis/reports/includes/old_intervention/amount.html' %} + {% include 'analysis/reports/includes/old_data/amount.html' %}
diff --git a/analysis/templates/analysis/reports/includes/old_intervention/amount.html b/analysis/templates/analysis/reports/includes/old_intervention/amount.html deleted file mode 100644 index 8a6b4be0..00000000 --- a/analysis/templates/analysis/reports/includes/old_intervention/amount.html +++ /dev/null @@ -1,30 +0,0 @@ -{% 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 %} -
-
- - - - - - - - - - - - - - - -
{% fa5_icon 'star' %} {% trans 'Checked' %}{% fa5_icon 'bookmark' %} {% trans 'Recorded' %}{% trans 'Total' %}
{{report.old_intervention_report.queryset_checked_count|default_if_zero:"-"}}{{report.old_intervention_report.queryset_recorded_count|default_if_zero:"-"}}{{report.old_intervention_report.queryset_count|default_if_zero:"-"}}
-
\ No newline at end of file diff --git a/analysis/utils/excel/excel.py b/analysis/utils/excel/excel.py index 69fbcdfe..611f6a0c 100644 --- a/analysis/utils/excel/excel.py +++ b/analysis/utils/excel/excel.py @@ -47,28 +47,30 @@ class TempExcelFile: Returns: """ - ws = self._workbook.active - # Always activate sheet protection - ws.protection.sheet = True - ws.protection.enable() - _rows = ws.iter_rows(start_row) - for row in _rows: - for cell in row: - val = cell.value - if val in self._template_map: - attr = self._template_map[val] - # If keyword '_iter' can be found inside the placeholder value it's an iterable and we - # need to process it differently - if isinstance(attr, dict): - # Read the iterable object and related attributes from the dict - _iter_obj = attr.get("iterable", None) - _attrs = attr.get("attrs", []) - self._add_cells_from_iterable(ws, cell, _iter_obj, _attrs) - # Since the sheet length did change now, we need to rerun this function starting with the new - # row counter - self._replace_template_placeholders(start_row=cell.row + len(_iter_obj)) - else: - cell.value = attr + sheets = self._workbook.worksheets + for sheet in sheets: + ws = sheet + # Always activate sheet protection + ws.protection.sheet = True + ws.protection.enable() + _rows = ws.iter_rows(start_row) + for row in _rows: + for cell in row: + val = cell.value + if val in self._template_map: + attr = self._template_map[val] + # If keyword '_iter' can be found inside the placeholder value it's an iterable and we + # need to process it differently + if isinstance(attr, dict): + # Read the iterable object and related attributes from the dict + _iter_obj = attr.get("iterable", None) + _attrs = attr.get("attrs", []) + self._add_cells_from_iterable(ws, cell, _iter_obj, _attrs) + # Since the sheet length did change now, we need to rerun this function starting with the new + # row counter + self._replace_template_placeholders(start_row=cell.row + len(_iter_obj)) + else: + cell.value = attr self._workbook.save(self._file.name) self._file.seek(0) self.stream = self._file.read() diff --git a/analysis/utils/excel/excel_report.xlsx b/analysis/utils/excel/excel_report.xlsx index 4383fbe8..72cf1295 100644 Binary files a/analysis/utils/excel/excel_report.xlsx and b/analysis/utils/excel/excel_report.xlsx differ diff --git a/analysis/utils/report.py b/analysis/utils/report.py index d3341a1a..1fd86604 100644 --- a/analysis/utils/report.py +++ b/analysis/utils/report.py @@ -379,14 +379,10 @@ class TimespanReport: self.queryset_registration_office_other_recorded_count = self.queryset_registration_office_other_recorded.count() class EcoAccountReport: - queryset_total = EcoAccount.objects.none() queryset = EcoAccount.objects.none() queryset_recorded = EcoAccount.objects.none() - queryset_old = EcoAccount.objects.none() - queryset_total_count = -1 queryset_count = -1 queryset_recorded_count = -1 - queryset_old_count = -1 queryset_deductions = 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): # First fetch all eco account for this office - self.queryset_total = EcoAccount.objects.filter( + self.queryset = 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( + self.queryset_recorded = self.queryset.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") @@ -427,15 +415,29 @@ class TimespanReport: intervention__recorded__isnull=False ) - self.queryset_total_count = self.queryset_total.count() self.queryset_count = self.queryset.count() - self.queryset_old_count = self.queryset_old.count() - self.queryset_recorded = self.queryset_recorded.count() + self.queryset_recorded_count = self.queryset_recorded.count() self.queryset_deductions_count = self.queryset_deductions.count() self.queryset_deductions_recorded_count = self.queryset_deductions_recorded.count() self.queryset_has_deductions_count = self.queryset_has_deductions.count() 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): """ Creates all report information @@ -453,32 +455,76 @@ class TimespanReport: sum=Sum("surface") )["sum"] or 0 - class OldInterventionReport: - queryset = Compensation.objects.none() - queryset_checked = Compensation.objects.none() - queryset_recorded = Compensation.objects.none() + class OldDataReport: + """ + Evaluates 'old data' (registered (zugelassen) before 16.06.2018) + """ + queryset_intervention = Intervention.objects.none() + queryset_intervention_recorded = Intervention.objects.none() + queryset_intervention_count = -1 + queryset_intervention_recorded_count = -1 - queryset_count = -1 - queryset_checked_count = -1 - queryset_recorded_count = -1 + queryset_comps = Compensation.objects.none() + queryset_comps_recorded = Compensation.objects.none() + 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): - self.queryset = Intervention.objects.filter( + self.queryset_intervention = 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 - ) - self.queryset_recorded = self.queryset.filter( + self.queryset_intervention_recorded = self.queryset_intervention.filter( recorded__isnull=False ) - self.queryset_count = self.queryset.count() - self.queryset_checked = self.queryset_checked.count() - self.queryset_recorded = self.queryset_recorded.count() + self.queryset_intervention_count = self.queryset_intervention.count() + self.queryset_intervention_recorded_count = self.queryset_intervention_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): self.office_id = office_id @@ -488,7 +534,7 @@ class TimespanReport: 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) + self.old_data_report = self.OldDataReport(self.office_id, date_from, date_to) # Build 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.compensation_report.excel_map) + self.excel_map.update(self.eco_account_report.excel_map) + self.excel_map.update(self.old_data_report.excel_map) diff --git a/locale/de/LC_MESSAGES/django.po b/locale/de/LC_MESSAGES/django.po index 764b7349..74b0ecab 100644 --- a/locale/de/LC_MESSAGES/django.po +++ b/locale/de/LC_MESSAGES/django.po @@ -77,7 +77,7 @@ msgstr "bis" #: 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 +#: analysis/templates/analysis/reports/includes/old_data/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 @@ -87,7 +87,7 @@ 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 +#: analysis/templates/analysis/reports/includes/old_data/amount.html:5 msgid "" "\n" " 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/eco_account/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 "" "\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/compensated_by.html:8 #: 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/templates/compensation/detail/compensation/view.html:43 #: 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/compensated_by.html:9 #: 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/templates/compensation/detail/compensation/view.html:57 #: 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/laws.html:23 #: 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:100 msgid "Total" @@ -185,7 +185,7 @@ msgid "Compensations" msgstr "Kompensationen" #: 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" msgstr "Vor" @@ -265,7 +265,7 @@ msgstr "" msgid "Law" 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" msgstr "Altfälle"