deplug calc in edit
[auf_rh_dae.git] / project / rh / views.py
CommitLineData
e9bbd6ba 1# -*- encoding: utf-8 -*-
c9122f1d 2from datetime import date
9b0a8554 3
3411ac33 4from django.contrib.auth.decorators import login_required
fd009814 5from django.utils.encoding import smart_str
e9bbd6ba 6from django.shortcuts import redirect, render_to_response, get_object_or_404
7from django.template import RequestContext
8
d04d084c 9from datamaster_modeles import models as ref
d04d084c 10from project.lib import get_employe_from_id
ae936f8d 11
d04d084c 12from rh import models as rh
e2c0b1ac 13from rh.lib import calc_remun
a9faef67 14
3411ac33 15# homes
c9122f1d 16@login_required
17def profil(request):
18 """Profil personnel de l'employé - éditable"""
19 rc = RequestContext(request)
20 c = {}
d04d084c 21
c9122f1d 22 employe = rc['this_employe']
65f9fac8 23
c9122f1d 24 c['user'] = request.user
25 c['employe'] = employe
c9122f1d 26 return render_to_response('rh/profil.html', c, rc)
a9faef67 27
28# employes
3411ac33 29@login_required
a9faef67 30def employes_liste(request):
31 """Liste des employés."""
5ea6b5bb 32 today = date.today()
33 employes = rh.Employe.objects \
34 .filter(actif=True, supprime=False) \
35 .filter(dossiers__actif=True, dossiers__supprime=False) \
36 .exclude(dossiers__date_debut__gt=today) \
37 .exclude(dossiers__date_fin__lt=today) \
38 .order_by('nom')
a9faef67 39 c = {
40 'user':request.user,
41 'employes':employes,
42 }
43 return render_to_response('rh/employes_liste.html', c, RequestContext(request))
44
3411ac33 45@login_required
a9faef67 46def employe(request, id):
47 """Information publique sur un employé."""
48 try:
49 employe = rh.Employe.objects.get(pk=id)
50 except:
51 employe = rh.Employe.objects.none()
52 c = {
53 'user':request.user,
54 'employe':employe,
55 }
56 return render_to_response('rh/employe.html', c, RequestContext(request))
63e17dff
PP
57
58
59# Rapports
60
61@login_required
62def rapports_poste(request):
63
fd009814
PP
64 lookup_params = dict(request.GET.items())
65
7821915f
PP
66 comble = 'all'
67
fd009814
PP
68 for key, value in lookup_params.items():
69 if not isinstance(key, str):
70 # 'key' will be used as a keyword argument later, so Python
71 # requires it to be a string.
72 del lookup_params[key]
73 lookup_params[smart_str(key)] = value
74
7821915f
PP
75 if key == 'comble':
76 comble = value
77 del lookup_params[key]
78
63e17dff 79 postes = rh.Poste.actifs.select_related('implantation').all()
fd009814
PP
80 postes = postes.filter(**lookup_params)
81
63e17dff
PP
82 poste_ids = set([p.pk for p in postes])
83
84 dossiers = rh.Dossier.objects.select_related('poste', 'employe').filter(poste__in=poste_ids)
85
86 employes = dict((d.poste.id, d.employe) for d in dossiers)
87
88 out = []
89
90 for p in postes:
7821915f
PP
91 employe = employes.get(p.id)
92
93 if comble == 'c' and not employe:
94 continue
95
96 if comble == 'n' and employe:
97 continue
98
63e17dff
PP
99 line = {}
100 out.append(line)
101
102 line['id'] = p.id
103 line['nom'] = p.nom
104 line['implantation'] = p.implantation.nom
63e17dff
PP
105 if employe:
106 line['employe_id'] = employe.id
107 line['employe_nom'] = employe.nom
108 line['employe_prenom'] = employe.prenom
109
110 c = {
111 'title': 'Rapport des postes',
112 'postes': out,
113 }
114
115 return render_to_response('rh/rapports/postes.html', c, RequestContext(request))
f2d65e83
PP
116
117
118def rapports_contrat(request):
119
120 lookup_params = dict(request.GET.items())
121
122 for key, value in lookup_params.items():
123 if not isinstance(key, str):
124 # 'key' will be used as a keyword argument later, so Python
125 # requires it to be a string.
126 del lookup_params[key]
127 lookup_params[smart_str(key)] = value
128
129 contrats = rh.Contrat.objects.select_related('dossier', 'dossier__poste', 'dossier__poste__implantation', 'type_contrat', 'dossier__employe').all()
130 contrats = contrats.filter(**lookup_params)
131
132 c = {
133 'title': 'Rapport des contrats',
134 'contrats': contrats,
135 }
136
137 return render_to_response('rh/rapports/contrats.html', c, RequestContext(request))
e2c0b1ac
PP
138
139
140def rapports_remuneration(request):
141
142 lookup_params = dict(request.GET.items())
143
144 for key, value in lookup_params.items():
145 if not isinstance(key, str):
146 # 'key' will be used as a keyword argument later, so Python
147 # requires it to be a string.
148 del lookup_params[key]
149 lookup_params[smart_str(key)] = value
150
151 employes = rh.Employe.objects.all()
152 employes = employes.filter(**lookup_params)
153
154 output = []
155
156 for employe in employes:
157 line = {}
158 output.append(line)
159
160 dossiers = employe.dossiers.all()
161
162 remun = {}
163 remun_sum_euro = 0
164
165 for dossier in dossiers:
166 this_remun, this_remun_sum, this_remun_sum_euro = calc_remun(dossier)
167
168 for item in this_remun:
169 if item not in remun:
170 remun[item] = this_remun[item]
171 else:
172 remun[item][0] += this_remun[item][0]
173 remun[item][1] += this_remun[item][1]
174
175 remun_sum_euro += this_remun_sum_euro
176
177 line['remun_sum_euro'] = remun_sum_euro
178
179 for r in remun:
180 if r == u'Indemnité':
e2c0b1ac
PP
181 line['Indemnite'] = remun[r][1]
182 else:
183 line[r] = remun[r][1]
184
185 line['id'] = employe.id
186 line['nom'] = employe.nom
187 line['prenom'] = employe.prenom
188
189
190 c = {
191 'title': 'Rapport de remuneration',
192 'employes': output,
193 }
194
195 return render_to_response('rh/rapports/remuneration.html', c, RequestContext(request))
3ebc0952
OL
196
197def dossier_apercu(request, dossier_id):
198 c = {
199 'is_popup' : request.GET.get('_popup', False),
200 'dossier' : get_object_or_404(rh.Dossier, pk=dossier_id)
201
202 }
203 return render_to_response('admin/rh/dossier/apercu.html', c, RequestContext(request))
4a1f2ece
OL
204
205def employe_apercu(request, employe_id):
206 employe = get_object_or_404(rh.Employe, pk=employe_id)
207 try:
208 dernier_dossier = rh.Dossier.objects.filter(employe=employe).order_by('-date_debut')[0]
209 except:
210 dernier_dossier = None
211
212 c = {
213 'is_popup' : request.GET.get('_popup', False),
214 'employe' : employe,
215 'dernier_dossier' : dernier_dossier,
216 }
217 return render_to_response('admin/rh/employe/apercu.html', c, RequestContext(request))