Skip to content

Commit

Permalink
feat(kesaseteli): add annual Excel download for previous year
Browse files Browse the repository at this point in the history
Tests are missing, product owner demanded this feature today.
  • Loading branch information
karisal-anders committed Feb 1, 2024
1 parent 02df04c commit 8eca4e7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ <h2>Työnantajien kesäsetelihakemukset:</h2>
<div class="col-xs-6">
<a href="{% url 'excel-download' %}?download=annual&columns=talpa" class="btn btn-secondary btn-lg active" role="button" aria-pressed="true">{% trans 'Lataa Talpa-Excel kaikista tämän vuoden hakemuksista' %}</a>
</div>
<hr/>
<p>
{% trans 'Luo uusi excel tiedosto kaikista järjestelmän viime vuoden hakemuksista. Tiedosto sisältää myös kaikki käsitellyt hakemukset.' %}
</p>
<div class="col-xs-6">
<a href="{% url 'excel-download' %}?download=annual-previous&columns=reporting" class="btn btn-secondary btn-lg active" role="button" aria-pressed="true">{% trans 'Lataa raportointi-Excel kaikista viime vuoden hakemuksista' %}</a>
</div>
<br/>
<div class="col-xs-6">
<a href="{% url 'excel-download' %}?download=annual-previous&columns=talpa" class="btn btn-secondary btn-lg active" role="button" aria-pressed="true">{% trans 'Lataa Talpa-Excel kaikista viime vuoden hakemuksista' %}</a>
</div>

<br/>
<h2>Nuorten kesäsetelihakemukset:</h2>
Expand Down
21 changes: 12 additions & 9 deletions backend/kesaseteli/applications/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,13 @@ def get(self, request, *args, **kwargs):
if request.GET.get("download") == "unhandled":
return self.export_and_download_unhandled_applications(columns)
elif request.GET.get("download") == "annual":
return self.export_and_download_annual_applications(columns)
return self.export_and_download_annual_applications(
columns, year=date.today().year
)
elif request.GET.get("download") == "annual-previous":
return self.export_and_download_annual_applications(
columns, year=date.today().year - 1
)
else:
return super().get(request, *args, **kwargs)

Expand Down Expand Up @@ -154,19 +160,16 @@ def export_and_download_unhandled_applications(
return response

def export_and_download_annual_applications(
self, columns: ExcelColumns
self, columns: ExcelColumns, year: int
) -> Union[StreamingHttpResponse, HttpResponseRedirect]:
"""
Export all applications from the ongoing year to xlsx file and download the file.
The file is returned as a response, thus automatically downloaded. The genearted xlsx
file will not be saved on disk and will not be shown on the xlsx files list.
Export all applications from the given year to xlsx file and download the file.
The file is returned as a response, thus automatically downloaded. The generated
xlsx file will not be saved on disk and will not be shown on the xlsx files list.
"""
start_of_year = date(date.today().year, 1, 1)
queryset = (
self.base_queryset()
.filter(
application__created_at__gte=start_of_year,
)
.filter(application__created_at__year=year)
.exclude(application__status=EmployerApplicationStatus.DRAFT)
)
if not queryset.exists():
Expand Down

0 comments on commit 8eca4e7

Please sign in to comment.