diff --git a/django-kitamanager/kitamanager/templates/kitamanager/child_list.html b/django-kitamanager/kitamanager/templates/kitamanager/child_list.html
index fbc0bf8..bea8a19 100644
--- a/django-kitamanager/kitamanager/templates/kitamanager/child_list.html
+++ b/django-kitamanager/kitamanager/templates/kitamanager/child_list.html
@@ -53,6 +53,7 @@
{{ object_list.count }} {% translate "children" %} ({{ historydate }})
+ {% translate "download as .csv" %}
{% include "kitamanager/child_table.inc.html" with object_list=object_list %}
diff --git a/django-kitamanager/kitamanager/templates/kitamanager/employee_list.html b/django-kitamanager/kitamanager/templates/kitamanager/employee_list.html
index fca9560..3e85961 100644
--- a/django-kitamanager/kitamanager/templates/kitamanager/employee_list.html
+++ b/django-kitamanager/kitamanager/templates/kitamanager/employee_list.html
@@ -90,6 +90,7 @@
{{ object_list.count }} {% translate "employees" %} ({{ historydate }})
+ {% translate "download as .csv" %}
{% include "kitamanager/employeecontract_table.inc.html" with object_list=object_list %}
diff --git a/django-kitamanager/kitamanager/tests/test_child_urls.py b/django-kitamanager/kitamanager/tests/test_child_urls.py
index bb8a7e8..c81f0e9 100644
--- a/django-kitamanager/kitamanager/tests/test_child_urls.py
+++ b/django-kitamanager/kitamanager/tests/test_child_urls.py
@@ -1,4 +1,5 @@
import pytest
+import datetime
from django.urls import reverse
from kitamanager.models import Child, ChildPaymentPlan, ChildPaymentTable, ChildPaymentTableEntry
from kitamanager.tests.common import _childcontract_create, _childpaymentplan_create
@@ -11,6 +12,19 @@ def test_child_list(admin_client):
assert response.status_code == 200
+@pytest.mark.django_db
+def test_child_list_csv(admin_client):
+ historydate = datetime.date.today()
+ response = admin_client.get(reverse("kitamanager:child-list-csv"))
+ assert response.status_code == 200
+ assert response.headers["Content-Type"] == "text/csv"
+ assert response.headers["Content-Disposition"] == f'attachment; filename="child-list-{historydate}.csv"'
+ assert (
+ response.content.decode()
+ == "ID,First Name,Last Name,Age,Voucher,Area,Pay tags,Requirement (full time person),Payment (Euro)\r\n"
+ )
+
+
@pytest.mark.django_db
def test_child_list_with_child_no_contract(admin_client):
Child.objects.create(first_name="1", last_name="11", birth_date="2017-10-22")
diff --git a/django-kitamanager/kitamanager/tests/test_employee_urls.py b/django-kitamanager/kitamanager/tests/test_employee_urls.py
index 49226ef..54b8588 100644
--- a/django-kitamanager/kitamanager/tests/test_employee_urls.py
+++ b/django-kitamanager/kitamanager/tests/test_employee_urls.py
@@ -1,4 +1,5 @@
import pytest
+import datetime
from django.urls import reverse
from kitamanager.tests.common import _employeecontract_create
from kitamanager.models import Employee, EmployeePaymentPlan, Area
@@ -21,6 +22,20 @@ def test_employee_list(admin_client):
assert response.status_code == 200
+@pytest.mark.django_db
+def test_employee_list_csv(admin_client):
+ historydate = datetime.date.today()
+ response = admin_client.get(reverse("kitamanager:employee-list-csv"))
+ assert response.status_code == 200
+ assert response.headers["Content-Type"] == "text/csv"
+ assert response.headers["Content-Disposition"] == f'attachment; filename="employee-list-{historydate}.csv"'
+ assert (
+ response.content.decode() == "ID,First Name,Last Name,Begin date,pay plan,pay group,pay level,pay "
+ "level next,area,qualification,hours child per week,hours management per week,"
+ "hours team per week,hours misc per week,monthly salary (Euro)\r\n"
+ )
+
+
@pytest.mark.django_db
def test_employee_detail(admin_client):
e = Employee.objects.create(first_name="1", last_name="11", birth_date="2017-10-22")
diff --git a/django-kitamanager/kitamanager/urls.py b/django-kitamanager/kitamanager/urls.py
index 2f05713..a584633 100644
--- a/django-kitamanager/kitamanager/urls.py
+++ b/django-kitamanager/kitamanager/urls.py
@@ -3,6 +3,7 @@
from django.contrib.auth import views as auth_views
from kitamanager.views_employee import (
employee_list,
+ employee_list_csv,
employee_detail,
employee_statistics,
employee_bonuspayment,
@@ -15,6 +16,7 @@
from kitamanager.views_bank import bankaccount_list, bankaccount_charts_sum_balance_by_month
from kitamanager.views_child import (
child_list,
+ child_list_csv,
child_list_future,
child_detail,
child_statistics,
@@ -42,6 +44,7 @@
path("employeepayment/", employeepayment_list, name="employeepayment-list"),
path("employeepayment//", employeepayment_detail, name="employeepayment-detail"),
path("employee/", employee_list, name="employee-list"),
+ path("employee/csv/", employee_list_csv, name="employee-list-csv"),
path("employee/statistics/", employee_statistics, name="employee-statistics"),
path("employee/bonus/", employee_bonuspayment, name="employee-bonuspayment"),
path("employee/check-sage-payroll", employee_check_sage_payroll, name="employee-check-sage-payroll"),
@@ -58,6 +61,7 @@
),
# child
path("child/", child_list, name="child-list"),
+ path("child/csv/", child_list_csv, name="child-list-csv"),
path("child/future/", child_list_future, name="child-list-future"),
path("child/statistics/", child_statistics, name="child-statistics"),
path("child//", child_detail, name="child-detail"),
diff --git a/django-kitamanager/kitamanager/views_child.py b/django-kitamanager/kitamanager/views_child.py
index 774382e..3c54723 100644
--- a/django-kitamanager/kitamanager/views_child.py
+++ b/django-kitamanager/kitamanager/views_child.py
@@ -7,8 +7,9 @@
from kitamanager.forms import HistoryDateForm
from kitamanager.models import Child, ChildContract, ChildPaymentPlan, ChildPaymentTable, RevenueEntry
from dateutil.relativedelta import relativedelta
-from django.http import JsonResponse
+from django.http import JsonResponse, HttpResponse
from kitamanager.definitions import CHART_COLORS, REVENUE_NAME_BERLIN
+import csv
@login_required
@@ -39,6 +40,57 @@ def child_list(request):
)
+@login_required
+def child_list_csv(request):
+ """
+ Get a list of children for the given date as CSV
+ """
+ historydate = datetime.date.today()
+ if request.method == "GET":
+ form = HistoryDateForm(request.GET)
+ if form.is_valid():
+ historydate = form.cleaned_data["historydate"]
+ else:
+ form = HistoryDateForm(initial={"historydate": historydate.strftime("%Y-%m-%d")})
+ else:
+ form = HistoryDateForm()
+
+ response = HttpResponse(
+ content_type="text/csv",
+ headers={"Content-Disposition": f'attachment; filename="child-list-{historydate}.csv"'},
+ )
+ writer = csv.writer(response)
+ # header row
+ writer.writerow(
+ [
+ "ID",
+ "First Name",
+ "Last Name",
+ "Age",
+ "Voucher",
+ "Area",
+ "Pay tags",
+ "Requirement (full time person)",
+ "Payment (Euro)",
+ ]
+ )
+ for child in ChildContract.objects.by_date(historydate):
+ writer.writerow(
+ [
+ child.person.pk,
+ child.person.first_name,
+ child.person.last_name,
+ child.person.age(historydate),
+ child.person.voucher,
+ child.area,
+ child.pay_tags,
+ child.requirement(historydate)[0],
+ child.payment(historydate),
+ ]
+ )
+ return response
+
+
@login_required
def child_list_future(request):
historydate = datetime.date.today()
diff --git a/django-kitamanager/kitamanager/views_employee.py b/django-kitamanager/kitamanager/views_employee.py
index eead91c..a8fee59 100644
--- a/django-kitamanager/kitamanager/views_employee.py
+++ b/django-kitamanager/kitamanager/views_employee.py
@@ -6,10 +6,11 @@
from kitamanager.sage_payroll import SagePayrolls
from django.utils.translation import gettext_lazy as _
import datetime
-from django.http import JsonResponse
+from django.http import JsonResponse, HttpResponse
from kitamanager.definitions import CHART_COLORS, SALARY_EMPLOYER_ADDITION
from decimal import Decimal
from typing import Dict, List
+import csv
@login_required
@@ -46,6 +47,69 @@ def employee_list(request):
)
+@login_required
+def employee_list_csv(request):
+ """
+ list available Employee for the given historydate and return as CSV
+ """
+ historydate = datetime.date.today()
+ if request.method == "GET":
+ form = HistoryDateForm(request.GET)
+ if form.is_valid():
+ historydate = form.cleaned_data["historydate"]
+ else:
+ form = HistoryDateForm(initial={"historydate": historydate.strftime("%Y-%m-%d")})
+ else:
+ form = HistoryDateForm()
+
+ response = HttpResponse(
+ content_type="text/csv",
+ headers={"Content-Disposition": f'attachment; filename="employee-list-{historydate}.csv"'},
+ )
+ writer = csv.writer(response)
+ # header row
+ writer.writerow(
+ [
+ "ID",
+ "First Name",
+ "Last Name",
+ "Begin date",
+ "pay plan",
+ "pay group",
+ "pay level",
+ "pay level next",
+ "area",
+ "qualification",
+ "hours child per week",
+ "hours management per week",
+ "hours team per week",
+ "hours misc per week",
+ "monthly salary (Euro)",
+ ]
+ )
+ for employee in EmployeeContract.objects.by_date(date=historydate):
+ writer.writerow(
+ [
+ employee.person.pk,
+ employee.person.first_name,
+ employee.person.last_name,
+ employee.person.begin_date,
+ employee.pay_plan.name,
+ employee.pay_group,
+ employee.pay_level,
+ employee.person.pay_level_next(historydate),
+ employee.area.name,
+ employee.qualification.name,
+ employee.hours_child,
+ employee.hours_management,
+ employee.hours_team,
+ employee.hours_misc,
+ employee.person.salary(historydate),
+ ]
+ )
+ return response
+
+
@login_required
def employeepayment_list(request):
"""