Skip to content

Commit

Permalink
DEFIVELO-225 Add export of salary data
Browse files Browse the repository at this point in the history
  • Loading branch information
OdyX authored and T4m committed Jan 18, 2022
1 parent 1884a6f commit d5730a3
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 0 deletions.
17 changes: 17 additions & 0 deletions apps/salary/templates/salary/timesheets_yearly_overview.html
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,23 @@ <h1 class="h3" style="display: inline">{% blocktrans %}Décompte salaires {{ yea
{% endfor %}
</tr>
{% endif %}
{% if user|can:'timesheet_control' %}
<tr>
<th>{% trans "Exports de contrôle" %}</th>
{% for month in months %}
<th class="text-center">
{% with "ods" as format %}
<a
title="{% blocktrans %}Télécharger au format {{ format }}{% endblocktrans %}"
class="btn btn-info"
href="{% url "salary:control-export" year=year month=forloop.counter format=format %}{% if canton %}?canton={{ canton }}{% endif %}">
<span class=" glyphicon glyphicon-floppy-save" ></span>
</a>
{% endwith %}
</th>
{% endfor %}
</tr>
{% endif %}
</tfoot>
</table>
{% else %}
Expand Down
6 changes: 6 additions & 0 deletions apps/salary/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from apps.salary.views import (
CleanupOrphanedTimesheets,
ExportMonthlyControl,
ExportMonthlyTimesheets,
RedirectUserMonthlyTimesheets,
SendTimesheetsReminder,
Expand Down Expand Up @@ -58,6 +59,11 @@
ExportMonthlyTimesheets.as_view(),
name="accounting-export",
),
url(
r"(?P<format>[a-z]+)-control$",
ExportMonthlyControl.as_view(),
name="control-export",
),
url(
r"^(?P<pk>[0-9]+)/$",
UserMonthlyTimesheets.as_view(),
Expand Down
1 change: 1 addition & 0 deletions apps/salary/views/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from .timesheets import (
CleanupOrphanedTimesheets,
ExportMonthlyControl,
ExportMonthlyTimesheets,
RedirectUserMonthlyTimesheets,
SendTimesheetsReminder,
Expand Down
83 changes: 83 additions & 0 deletions apps/salary/views/timesheets.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from django.utils import formats, timezone, translation
from django.utils.datastructures import OrderedSet
from django.utils.dates import MONTHS_3
from django.utils.text import format_lazy
from django.utils.translation import ngettext as n
from django.utils.translation import ugettext as u
from django.utils.translation import ugettext_lazy as _
Expand All @@ -25,6 +26,7 @@
from apps.challenge.models.session import Session
from apps.common import DV_STATE_CHOICES
from apps.common.views import ExportMixin
from apps.salary import BONUS_LEADER, HOURLY_RATE_HELPER, RATE_ACTOR
from apps.salary.forms import ControlTimesheetFormSet, TimesheetFormSet
from apps.salary.models import Timesheet
from defivelo.roles import has_permission
Expand Down Expand Up @@ -366,6 +368,87 @@ def get_dataset(self, html=False):
return dataset


class ExportMonthlyControl(ExportMixin, MonthArchiveView):
date_field = "date"
month_format = "%m"
allow_empty = True
allow_future = True
model = Timesheet

def get_queryset(self):
active_canton = self.request.GET.get("canton")
users = timesheets_overview.get_visible_users(self.request.user).order_by(
"first_name", "last_name"
)
if active_canton:
users = users.filter(profile__affiliation_canton=active_canton)
return super().get_queryset().filter(validated_at__isnull=False, user__in=users)

def get_dataset_title(self):
return _("Export de contrôle {month} {year}").format(
month=self.get_month(), year=self.get_year()
)

@property
def export_filename(self):
return f"export-control-{self.get_year()}-{self.get_month()}"

def get_dataset(self, html=False):
dataset = Dataset()
dataset.headers = [
u("Numéro d’employé Crésus"),
u("Prénom"),
u("Nom"),
format_lazy(
u("Heures moni·teur·trice ({price}.-/h)"), price=HOURLY_RATE_HELPER
),
format_lazy(u("Intervention(s) ({price}.-/Qualif’)"), price=RATE_ACTOR),
format_lazy(
u("Participation(s) comme moni·teur·trice 2 ({price}.-/Qualif’)"),
price=BONUS_LEADER,
),
format_lazy(
u("Heures supplémentaires ({price}.-/h)"), price=HOURLY_RATE_HELPER
),
u("Heures de trajet (aller-retour)"),
u("Total heures"),
u("Total CHF"),
# u("Ne compter aucune heure de travail"),
]

_, object_list, _ = self.get_dated_items()

for salary_details in timesheets_overview.get_salary_details_list(
object_list
).order_by("first_name"):
time_total = (
salary_details["time_helper"]
+ salary_details["overtime"]
+ salary_details["traveltime"]
)
chf_total = (
time_total * HOURLY_RATE_HELPER
+ salary_details["actor_count"] * RATE_ACTOR
+ salary_details["leader_count"] * BONUS_LEADER
)
dataset.append(
[
# See DEFIVELO-225
salary_details["employee_code"],
salary_details["first_name"],
salary_details["last_name"],
salary_details["time_helper"],
salary_details["actor_count"],
salary_details["leader_count"],
salary_details["overtime"],
salary_details["traveltime"],
time_total,
chf_total,
]
)
return dataset


class CleanupOrphanedTimesheets(TemplateView):
template_name = "salary/cleanup_orphaned_timesheets.html"
required_permission = "timesheet_editor"
Expand Down
1 change: 1 addition & 0 deletions defivelo/roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class PowerUser(AbstractUserRole):
"challenge_season_see_state_planning": True,
"settings_crud": True,
"timesheet": True,
"timesheet_control": True,
"timesheet_editor": True,
}

Expand Down

0 comments on commit d5730a3

Please sign in to comment.