SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit 100a19ac authored by Jorran de Wit's avatar Jorran de Wit
Browse files

Finish new finance tempalte

parent 2ecc0725
No related branches found
No related tags found
No related merge requests found
...@@ -74,8 +74,33 @@ class LogsFilter(forms.Form): ...@@ -74,8 +74,33 @@ class LogsFilter(forms.Form):
def get_months(self): def get_months(self):
return self.cleaned_data['months'] return self.cleaned_data['months']
def filter(self):
"""Filter work logs and return in user-grouped format."""
output = []
if self.is_valid():
if self.cleaned_data['employee']:
user_qs = get_user_model().objects.filter(id=self.cleaned_data['employee'].id)
else:
user_qs = get_user_model().objects.filter(work_logs__isnull=False)
user_qs = user_qs.filter(
work_logs__work_date__gte=self.cleaned_data['start'],
work_logs__work_date__lte=self.cleaned_data['end']).distinct()
output = []
for user in user_qs:
logs = user.work_logs.filter(
work_date__gte=self.cleaned_data['start'],
work_date__lte=self.cleaned_data['end']).distinct()
output.append({
'logs': logs,
'duration': logs.aggregate(total=Sum('duration')),
'user': user,
})
return output
def filter_per_month(self): def filter_per_month(self):
"""Filter work logs and return in convenient format.""" """Filter work logs and return in per-month format."""
output = [] output = []
if self.is_valid(): if self.is_valid():
if self.cleaned_data['employee']: if self.cleaned_data['employee']:
......
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
{% if form.is_bound %} {% if form.is_bound %}
<h2 class="mb-2 mt-4">Team timesheets</h2> <h2 class="mb-2 mt-4">Team timesheets</h2>
<h4 class="mb-1">{{ user_log.user.first_name }} {{ user_log.user.last_name }}</h4> <h4 class="mb-1">{{ user_log.user.first_name }} {{ user_log.user.last_name }}</h4>
<table class="table"> <table class="table table-hover">
<thead class="thead-default"> <thead class="thead-default">
<tr> <tr>
<th>Employee</th> <th>Employee</th>
...@@ -53,7 +53,7 @@ ...@@ -53,7 +53,7 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{% for user_log in form.filter %} {% for user_log in form.filter_per_month %}
<tr> <tr>
<td>{{ user_log.user.last_name }}, {{ user_log.user.first_name }}</td> <td>{{ user_log.user.last_name }}, {{ user_log.user.first_name }}</td>
{% for log in user_log.logs %} {% for log in user_log.logs %}
......
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
<h2 class="mb-2 mt-4">Team timesheets</h2> <h2 class="mb-2 mt-4">Team timesheets</h2>
{% for user_log in form.filter %} {% for user_log in form.filter %}
<h4 class="mb-1">{{ user_log.user.first_name }} {{ user_log.user.last_name }}</h4> <h4 class="mb-1">{{ user_log.user.first_name }} {{ user_log.user.last_name }}</h4>
<table class="table"> <table class="table table-hover">
<thead class="thead-default"> <thead class="thead-default">
<tr> <tr>
<th>Date</th> <th>Date</th>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment