trop de données
[auf_rh_dae.git] / project / rh / lib.py
CommitLineData
6e7c919b
NC
1# -*- encoding: utf-8 -*-
2
8d3e2fff
PP
3from collections import defaultdict
4import datetime
5
babf71ec 6from django.db import models
cb527994 7from django import forms
790b9793 8from django.core.urlresolvers import reverse
6e7c919b 9from django.contrib import admin
49449367 10from django.conf import settings
aff1a4c6 11from django.db.models import Q
d6985a3a 12from auf.django.metadata.admin import AUFMetadataAdminMixin, AUFMetadataInlineAdminMixin, AUF_METADATA_READONLY_FIELDS
babf71ec 13from project.rh import models as rh
84cbb4c5 14from forms import DossierForm, ContratForm
aff1a4c6
PP
15from dae.utils import get_employe_from_user
16
17
cb527994 18
6318ebea
PP
19# Override of the InlineModelAdmin to support the link in the tabular inline
20class LinkedInline(admin.options.InlineModelAdmin):
21 template = "admin/linked.html"
22 admin_model_path = None
23
24 def __init__(self, *args):
25 super(LinkedInline, self).__init__(*args)
26 if self.admin_model_path is None:
27 self.admin_model_path = self.model.__name__.lower()
28
29
aff1a4c6
PP
30class ProtectRegionMixin(object):
31
32 def queryset(self, request):
32373f2e 33 from dae.workflow import grp_drh, grp_correspondants_rh
aff1a4c6
PP
34 qs = super(ProtectRegionMixin, self).queryset(request)
35
36 if request.user.is_superuser:
37 return qs
38
32373f2e 39 user_groups = request.user.groups.all()
aff1a4c6 40
32373f2e
OL
41 if grp_drh in user_groups:
42 return qs
43
44 if grp_correspondants_rh in user_groups:
45 employe = get_employe_from_user(request.user)
46 q = Q(**{self.model.prefix_implantation: employe.implantation.region})
47 qs = qs.filter(q).distinct()
48 return qs
49 return qs.none()
aff1a4c6
PP
50
51 def has_change_permission(self, request, obj=None):
52 if request.user.is_superuser:
53 return True
54
55 if obj:
56 employe = get_employe_from_user(request.user)
57 if employe.implantation.region in obj.get_regions():
58 return True
59 else:
60 return False
61
62 return True
63
6e7c919b 64
d6985a3a 65# Inlines
6e7c919b 66
d6985a3a
OL
67class ReadOnlyInlineMixin(object):
68 def get_readonly_fields(self, request, obj=None):
69 return [f.name for f in self.model._meta.fields if f.name not in AUF_METADATA_READONLY_FIELDS]
6e7c919b
NC
70
71
51ab4c2c 72class AyantDroitInline(AUFMetadataInlineAdminMixin, admin.StackedInline):
babf71ec 73 model = models.Model # à remplacer dans admin.py
51ab4c2c 74 extra = 0
54d04eed 75
972f50e4
PP
76 fieldsets = (
77 (None, {
78 'fields': (('nom', 'prenom'), ('nom_affichage', 'genre'), 'nationalite', 'date_naissance', 'lien_parente', )
79 }),
80 )
81
d6985a3a
OL
82
83class AyantDroitCommentaireInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
cf786fb2 84 readonly_fields = ('owner', )
babf71ec 85 model = models.Model # à remplacer dans admin.py
cf786fb2 86 extra = 1
6e7c919b 87
54d04eed 88
d6985a3a 89class ContratInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
84cbb4c5 90 form = ContratForm
babf71ec 91 model = models.Model # à remplacer dans admin.py
1f2979b8 92 extra = 1
babf71ec
NC
93
94
6318ebea 95class DossierROInline(ReadOnlyInlineMixin, LinkedInline):
3ebc0952 96 template = "admin/rh/dossier/linked.html"
d6985a3a 97 exclude = AUF_METADATA_READONLY_FIELDS
babf71ec 98 model = models.Model # à remplacer dans admin.py
54773196 99 extra = 0
52688246
OL
100 can_delete = False
101
0e190851 102 def has_add_permission(self, request=None):
52688246
OL
103 return False
104
105 def has_change_permission(self, request, obj=None):
106 return False
107
108 def has_delete_permission(self, request, obj=None):
109 return False
babf71ec 110
d6985a3a
OL
111
112class DossierCommentaireInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
1f2979b8 113 readonly_fields = ('owner', )
babf71ec 114 model = models.Model # à remplacer dans admin.py
1f2979b8 115 extra = 1
babf71ec 116
d6985a3a 117
babf71ec
NC
118class DossierPieceInline(admin.TabularInline):
119 model = models.Model # à remplacer dans admin.py
988af3fb 120 extra = 4
babf71ec
NC
121
122
123class EmployeInline(admin.TabularInline):
124 model = models.Model # à remplacer dans admin.py
125
d6985a3a 126class EmployeCommentaireInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
cf786fb2 127 readonly_fields = ('owner', )
babf71ec 128 model = models.Model # à remplacer dans admin.py
cf786fb2 129 extra = 1
babf71ec
NC
130
131
132class EmployePieceInline(admin.TabularInline):
133 model = models.Model # à remplacer dans admin.py
988af3fb 134 extra = 4
babf71ec
NC
135
136
d6985a3a 137class EvenementInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
babf71ec 138 model = models.Model # à remplacer dans admin.py
1f2979b8 139 extra = 1
babf71ec
NC
140
141
d6985a3a 142class EvenementRemunerationInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
babf71ec 143 model = models.Model # à remplacer dans admin.py
1f2979b8 144 extra = 1
babf71ec
NC
145
146
d6985a3a 147class PosteCommentaireInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
70561dc2 148 readonly_fields = ('owner', )
babf71ec 149 model = models.Model # à remplacer dans admin.py
70561dc2 150 extra = 1
babf71ec
NC
151
152
153class PosteFinancementInline(admin.TabularInline):
154 model = models.Model # à remplacer dans admin.py
155
156
157class PostePieceInline(admin.TabularInline):
158 model = models.Model # à remplacer dans admin.py
159
160
d6985a3a 161class RemunerationInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
babf71ec 162 model = models.Model # à remplacer dans admin.py
1f2979b8 163 extra = 1
babf71ec
NC
164
165
d6985a3a 166class RemunerationROInline(ReadOnlyInlineMixin, RemunerationInline):
6e7c919b
NC
167 pass
168
54d04eed 169
26dacccc 170class TypePosteInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
babf71ec
NC
171 model = models.Model # à remplacer dans admin.py
172
173
174# Admins
175
aff1a4c6 176class AyantDroitAdmin(AUFMetadataAdminMixin, ProtectRegionMixin, admin.ModelAdmin):
cf786fb2
OL
177 """
178 L'ajout d'un nouvel ayantdroit se fait dans l'admin de l'employé.
179 """
387ab827 180 alphabet_filter = 'nom'
cf786fb2 181 search_fields = ('nom', 'prenom', 'employe__nom', 'employe__prenom', )
1a89b1f3 182 list_display = ('_employe', 'lien_parente', '_ayantdroit', )
babf71ec 183 inlines = (AyantDroitCommentaireInline,)
d6985a3a
OL
184 readonly_fields = AUFMetadataAdminMixin.readonly_fields + ('employe',)
185 fieldsets = AUFMetadataAdminMixin.fieldsets + (
cf786fb2 186 ("Lien avec l'employé", {
76e26dfc 187 'fields': (('employe', 'lien_parente'), )
cf786fb2
OL
188 }),
189
190 ('Identification', {
76e26dfc 191 'fields': (('nom', 'prenom'), ('nom_affichage', 'genre'), 'nationalite', 'date_naissance', )
cf786fb2
OL
192 }),
193 )
194
195 def save_formset(self, request, form, formset, change):
196 instances = formset.save(commit=False)
197 for instance in instances:
198 if instance.__class__ == rh.AyantDroitCommentaire:
199 instance.owner = request.user
200 instance.save()
cf786fb2
OL
201
202 def _ayantdroit(self, obj):
203 return unicode(obj)
204 _ayantdroit.short_description = u'Ayant droit'
babf71ec 205
cf786fb2
OL
206 def _employe(self, obj):
207 return unicode(obj.employe)
208 _employe.short_description = u'Employé'
209
210 def has_add_permission(self, request):
211 return False
babf71ec
NC
212
213class AyantDroitCommentaireAdmin(admin.ModelAdmin):
6e7c919b
NC
214 pass
215
54d04eed 216
324bf312
OL
217class ClassementAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
218 fieldsets = AUFMetadataAdminMixin.fieldsets + (
219 (None, {
220 'fields': ('type', 'echelon', 'degre', 'coefficient', )
221 }),
222 )
223
6e7c919b 224
6e7c919b
NC
225class CommentaireAdmin(admin.ModelAdmin):
226 pass
227
228
84cbb4c5
OL
229#class ContratAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
230# form = ContratForm
231# alphabet_filter = 'dossier__employe__nom'
232# search_fields = ('dossier__employe__nom', 'dossier__employe__prenom', 'dossier__poste__nom', 'dossier__poste__nom_feminin', )
233# list_display = ('id', '_employe', '_poste', 'date_debut', 'date_fin', '_implantation', )
234# fieldsets = AUFMetadataAdminMixin.fieldsets + (
235# (None, {
236# 'fields': ('dossier', 'type_contrat', 'date_debut', 'date_fin', )
237# }),
238# )
239#
240# def lookup_allowed(self, key, value):
241# if key in ('dossier__employe__nom__istartswith', ):
242# return True
243#
244# def _employe(self, obj):
245# return unicode(obj.dossier.employe)
246# _employe.short_description = "Employé"
247#
248# def _poste(self, obj):
249# return obj.dossier.poste.nom
250# _poste.short_description = "Poste"
251#
252# def _implantation(self, obj):
253# return obj.dossier.poste.implantation
254# _poste.short_description = "Implantation"
54d04eed 255
84fc088b
OL
256class DeviseAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
257 fieldsets = AUFMetadataAdminMixin.fieldsets + (
258 (None, {
259 'fields': ('code', 'nom', ),
260 }),
261 )
6e7c919b 262
54d04eed 263
aff1a4c6 264class DossierAdmin(AUFMetadataAdminMixin, ProtectRegionMixin, admin.ModelAdmin,):
84cbb4c5 265 form = DossierForm
387ab827 266 alphabet_filter = 'employe__nom'
d8d7985b 267 search_fields = ('employe__nom', 'employe__prenom', 'poste__nom', 'poste__nom_feminin')
150d83ec 268 list_display = ('_id', '_employe', '_actif', '_poste', 'date_debut', 'date_fin', 'date_modification')
fd2323c8 269 list_filter = ('poste__implantation__region', 'poste__implantation', )
1f2979b8 270 inlines = (DossierPieceInline, ContratInline,
cf786fb2
OL
271 RemunerationInline,
272 #EvenementInline,
273 DossierCommentaireInline,
1f2979b8 274 )
d6985a3a 275 fieldsets = AUFMetadataAdminMixin.fieldsets + (
5961a2c9 276 (None, {
7ac30609 277 'fields': ('employe', 'poste', 'statut', 'organisme_bstg',)
1f2979b8
OL
278 }),
279 ('Recrutement', {
7c182958 280 'fields': ('statut_residence', 'remplacement', 'remplacement_de', )
1f2979b8
OL
281 }),
282 ('Rémunération', {
cb962802 283 'fields': ('classement', ('regime_travail', 'regime_travail_nb_heure_semaine'),)
1f2979b8
OL
284 }),
285 ('Occupation du Poste par cet Employe', {
cb962802 286 'fields': (('date_debut', 'date_fin'), )
1f2979b8
OL
287 }),
288 )
54d04eed 289
7c182958
PP
290 class Media:
291 js = ('js/dossier.js',)
292
387ab827 293 def lookup_allowed(self, key, value):
150d83ec
OL
294 if key in (
295 'employe__nom__istartswith',
296 'actif__exact',
b4c7b7ca
OL
297 'poste__implantation__region__id__exact',
298 'poste__implantation__id__exact',
150d83ec 299 ):
387ab827
OL
300 return True
301
150d83ec
OL
302 def _id(self, d):
303 link = u"""<a onclick="return showAddAnotherPopup(this);" href='%s'>%s</a> <a href="%s" title="Modifier le dossier"><img src="%simg/page_edit.png" /></a>""" % \
304 (reverse('dossier_apercu', args=(d.id,)),
305 d.id,
306 reverse('admin:rh_dossier_change', args=(d.id,)),
307 settings.MEDIA_URL,
308 )
309 return link
310 _id.allow_tags = True
311 _id.short_description = u'Numéro de dossier'
312 _id.admin_order_field = 'id'
313
314
49449367
OL
315 def _actif(self, dossier):
316 if dossier.employe.actif:
317 html = """<img alt="True" src="%simg/admin/icon-yes.gif">"""
318 else:
319 html = """<img alt="False" src="%simg/admin/icon-no.gif">"""
320 return html % settings.ADMIN_MEDIA_PREFIX
150d83ec 321 _actif.allow_tags = True
49449367
OL
322 _actif.short_description = u'Employé actif'
323 _actif.admin_order_field = 'employe__actif'
387ab827 324
54d04eed 325 def _poste(self, dossier):
150d83ec
OL
326 link = u"""<a onclick="return showAddAnotherPopup(this);" href='%s'>%s</a> <a href="%s" title="Modifier le poste"><img src="%simg/page_edit.png" /></a>""" % \
327 (reverse('poste_apercu', args=(dossier.poste.id,)),
328 dossier.poste,
329 reverse('admin:rh_poste_change', args=(dossier.poste.id,)),
330 settings.MEDIA_URL,
331 )
332 return link
333 _poste.allow_tags = True
54d04eed 334 _poste.short_description = u'Poste'
d9836879 335 _poste.admin_order_field = 'poste__nom'
54d04eed 336
150d83ec
OL
337 def _employe(self, obj):
338 employe = obj.employe
339 view_link = reverse('employe_apercu', args=(employe.id,))
340 edit_link = reverse('admin:rh_employe_change', args=(employe.id,))
341 return u"""<a onclick="return showAddAnotherPopup(this);" href='%s'>[%s] %s %s</a>
342 <a href="%s" title="Modifier l'employé"><img src="%simg/user_edit.png" /></a>""" % \
343 (view_link, employe.id, employe.nom.upper(), employe.prenom.title(), edit_link, settings.MEDIA_URL,)
344 _employe.allow_tags = True
345 _employe.short_description = u"Employé ([code] NOM Prénom)"
346 _employe.admin_order_field = "employe__nom"
d9836879 347
1f2979b8
OL
348 def save_formset(self, request, form, formset, change):
349 instances = formset.save(commit=False)
350 for instance in instances:
351 if instance.__class__ == rh.DossierCommentaire:
352 instance.owner = request.user
353 instance.save()
6e7c919b 354
8d3e2fff 355
6e7c919b
NC
356class DossierPieceAdmin(admin.ModelAdmin):
357 pass
358
54d04eed 359
6e7c919b
NC
360class DossierCommentaireAdmin(admin.ModelAdmin):
361 pass
362
54d04eed 363
cb527994
PP
364class EmployeAdminForm(forms.ModelForm):
365 class Meta:
366 model = rh.Employe
367
368 def __init__(self, *args, **kwargs):
369 super(EmployeAdminForm, self).__init__(*args, **kwargs)
52688246 370 self.fields['date_naissance'].widget = forms.widgets.DateInput()
cb527994
PP
371
372
aff1a4c6 373class EmployeAdmin(AUFMetadataAdminMixin, ProtectRegionMixin, admin.ModelAdmin):
7ffc5aa4 374 alphabet_filter = 'nom'
2a333057 375 DEFAULT_ALPHABET = u'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
64721a83 376 search_fields = ('id', 'nom', 'prenom', 'nom_affichage', )
49449367
OL
377 ordering = ('nom', )
378 actions = ('desactiver', )
cb527994 379 form = EmployeAdminForm
4a1f2ece 380 list_display = ('_nom', '_dossiers', 'date_modification', 'user_modification',)
2580a2d9 381 list_filter = ('dossiers__poste__implantation__region', 'dossiers__poste__implantation', 'actif', )
babf71ec
NC
382 inlines = (AyantDroitInline,
383 DossierROInline,
384 EmployePieceInline,
385 EmployeCommentaireInline)
64721a83 386 fieldsets = AUFMetadataAdminMixin.fieldsets + (
cf786fb2 387 ('Identification', {
e35610f5 388 'fields': (('nom', 'prenom'), ('nom_affichage', 'genre'), 'nationalite', 'date_naissance', )
cf786fb2
OL
389 }),
390 ('Informations personnelles', {
391 'fields': ('situation_famille', 'date_entree', )
392 }),
393 ('Coordonnées', {
e35610f5 394 'fields': (('tel_domicile', 'tel_cellulaire'), ('adresse', 'ville'), ('code_postal', 'province'), 'pays', )
cf786fb2
OL
395 }),
396 )
babf71ec 397
4a1f2ece
OL
398 def _nom(self, obj):
399 view_link = reverse('employe_apercu', args=(obj.id,))
400 edit_link = reverse('admin:rh_employe_change', args=(obj.id,))
401 return u"""<a onclick="return showAddAnotherPopup(this);" href='%s'>[%s] %s %s</a>
402 <a href="%s" title="Modifier l'employé"><img src="%simg/user_edit.png" /></a>""" % \
403 (view_link, obj.id, obj.nom.upper(), obj.prenom.title(), edit_link, settings.MEDIA_URL,)
404 _nom.allow_tags = True
405 _nom.short_description = u"Employé ([code] NOM Prénom)"
406 _nom.admin_order_field = "nom"
407
790b9793
OL
408 def _dossiers(self, obj):
409 l = []
410 for d in obj.dossiers.all().order_by('-date_debut'):
3ebc0952
OL
411 style = ""
412 if d.date_fin is not None:
413 style = "color: grey";
4a1f2ece 414 link = u"""<li><a style="%s;" onclick="return showAddAnotherPopup(this);" href='%s'>%s : %s</a> <a href="%s" title="Modifier le dossier"><img src="%simg/page_edit.png" /></a> </li>""" % \
3ebc0952
OL
415 (style,
416 reverse('dossier_apercu', args=(d.id,)),
790b9793 417 d.date_debut.year,
4a1f2ece
OL
418 d.poste,
419 reverse('admin:rh_dossier_change', args=(d.id,)),
420 settings.MEDIA_URL,
421 )
790b9793
OL
422 l.append(link)
423 return "<ul>%s</ul>" % "\n".join(l)
424 _dossiers.allow_tags = True
425
64721a83 426 def queryset(self, request):
7eb1ab09 427 qs = super(EmployeAdmin, self).queryset(request)
2a333057 428 return qs.filter(actif=True).select_related(depth=1).order_by('nom')
64721a83 429
cf786fb2
OL
430 def save_formset(self, request, form, formset, change):
431 instances = formset.save(commit=False)
432 for instance in instances:
433 if instance.__class__ == rh.EmployeCommentaire:
434 instance.owner = request.user
435 instance.save()
babf71ec 436
2d5533ac
PP
437
438
babf71ec 439class EmployeCommentaireAdmin(admin.ModelAdmin):
6e7c919b
NC
440 pass
441
54d04eed 442
babf71ec 443class EmployePieceAdmin(admin.ModelAdmin):
6e7c919b
NC
444 pass
445
54d04eed 446
6e7c919b 447class EvenementAdmin(admin.ModelAdmin):
babf71ec 448 inlines = (EvenementRemunerationInline,)
6e7c919b 449
54d04eed 450
6e7c919b
NC
451class EvenementRemunerationAdmin(admin.ModelAdmin):
452 pass
453
54d04eed 454
26dacccc 455class FamilleEmploiAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
babf71ec 456 inlines = (TypePosteInline,)
26dacccc
OL
457 fieldsets = AUFMetadataAdminMixin.fieldsets + (
458 (None, {
459 'fields': ('nom', )
460 }),
461 )
6e7c919b 462
54d04eed 463
aff1a4c6 464class OrganismeBstgAdmin(AUFMetadataAdminMixin, ProtectRegionMixin, admin.ModelAdmin):
d8d7985b 465 search_fields = ('nom', )
1c8856ef 466 list_display = ('nom', 'type', 'pays', )
babf71ec 467 inlines = (DossierROInline,)
43f5653a
OL
468 fieldsets = AUFMetadataAdminMixin.fieldsets + (
469 (None, {
470 'fields': ('nom', 'type', 'pays', )
471 }),
472 )
6e7c919b 473
54d04eed 474
aff1a4c6 475class PosteAdmin(AUFMetadataAdminMixin, ProtectRegionMixin, admin.ModelAdmin):
387ab827 476 alphabet_filter = 'nom'
23102192
DB
477 search_fields = ('nom',
478 'implantation__code',
479 'implantation__nom',
480 'implantation__region__code',
481 'implantation__region__nom',
482 )
150d83ec
OL
483 list_display = (
484 '_nom',
23102192
DB
485 '_occupe_par',
486 'implantation',
487 'service',
23102192
DB
488 'date_debut',
489 'date_fin',
490 'date_modification',
491 'user_modification',
492 )
493 list_filter = ('service',
494 'implantation__region',
23102192
DB
495 'implantation',
496 )
d2cf315a 497 fieldsets = AUFMetadataAdminMixin.fieldsets + (
6e7c919b 498 (None, {
4497b3cb 499 'fields': (('nom', 'nom_feminin'), 'implantation', 'type_poste',
6e7c919b
NC
500 'service', 'responsable')
501 }),
502 ('Contrat', {
4497b3cb 503 'fields': (('regime_travail', 'regime_travail_nb_heure_semaine'), )
6e7c919b
NC
504 }),
505 ('Recrutement', {
4497b3cb 506 'fields': (('local', 'expatrie', 'mise_a_disposition', 'appel'),)
6e7c919b
NC
507 }),
508 ('Rémunération', {
4497b3cb
PP
509 'fields': (('classement_min', 'classement_max'),
510 ('valeur_point_min', 'valeur_point_max'),
511 ('devise_min', 'devise_max'),
512 ('salaire_min', 'salaire_max'),
513 ('indemn_min', 'indemn_max'),
514 ('autre_min', 'autre_max'))
6e7c919b
NC
515 }),
516 ('Comparatifs de rémunération', {
4497b3cb
PP
517 'fields': ('devise_comparaison',
518 ('comp_locale_min', 'comp_locale_max'),
519 ('comp_universite_min', 'comp_universite_max'),
520 ('comp_fonctionpub_min', 'comp_fonctionpub_max'),
521 ('comp_ong_min', 'comp_ong_max'),
522 ('comp_autre_min', 'comp_autre_max'))
6e7c919b
NC
523 }),
524 ('Justification', {
525 'fields': ('justification',)
526 }),
527 ('Autres Metadata', {
4497b3cb 528 'fields': ('date_validation', ('date_debut', 'date_fin'))
6e7c919b
NC
529 }),
530 )
531
babf71ec
NC
532 inlines = (PosteFinancementInline,
533 PostePieceInline,
70561dc2
OL
534 DossierROInline,
535 PosteCommentaireInline, )
6e7c919b 536
150d83ec
OL
537 def _nom(self, poste):
538 link = u"""<a onclick="return showAddAnotherPopup(this);" href='%s'>%s</a> <a href="%s" title="Modifier le poste"><img src="%simg/page_edit.png" /></a>""" % \
539 (reverse('poste_apercu', args=(poste.id,)),
540 poste.nom,
541 reverse('admin:rh_poste_change', args=(poste.id,)),
542 settings.MEDIA_URL,
543 )
544 return link
545 _nom.allow_tags = True
546 _nom.short_description = u'Nom'
547 _nom.admin_order_field = 'nom'
548
23102192
DB
549 def _occupe_par(self, obj):
550 """Formatte la méthode Poste.occupe_par() pour l'admin"""
551 output = "VACANT"
552 employes = obj.occupe_par()
553 if employes:
554 l = []
555 for e in employes:
556 link = "<a href='%s'>%s</a>" % \
557 (reverse('admin:rh_employe_change', args=(e.id,)),
558 e)
559 l.append(link)
560 output = "\n<br />".join(l)
561 return output
562 _occupe_par.allow_tags = True
563 _occupe_par.short_description = "Occupé par"
564
70561dc2
OL
565 def save_formset(self, request, form, formset, change):
566 instances = formset.save(commit=False)
567 for instance in instances:
568 if instance.__class__ == rh.PosteCommentaire:
569 instance.owner = request.user
570 instance.save()
571 formset.save_m2m()
6e7c919b 572
aff1a4c6 573
6e7c919b
NC
574class PosteCommentaireAdmin(admin.ModelAdmin):
575 pass
576
6e7c919b 577
babf71ec 578class PosteFinancementAdmin(admin.ModelAdmin):
6e7c919b
NC
579 pass
580
6e7c919b 581
babf71ec 582class PostePieceAdmin(admin.ModelAdmin):
6e7c919b
NC
583 pass
584
6e7c919b 585
babf71ec 586class RemunerationAdmin(admin.ModelAdmin):
6e7c919b
NC
587 pass
588
6e7c919b 589
1eede0db
OL
590class ResponsableImplantationAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
591 fieldsets = AUFMetadataAdminMixin.fieldsets + (
592 (None, {
593 'fields': ('employe', 'implantation', ),
594 }),
595 )
596
6e7c919b 597
43f5653a
OL
598class ServiceAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
599 list_display = ('nom', 'actif', )
600 fieldsets = AUFMetadataAdminMixin.fieldsets + (
601 (None, {
602 'fields': ('nom', ),
603 }),
604 )
6e7c919b 605
43f5653a
OL
606class StatutAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
607 fieldsets = AUFMetadataAdminMixin.fieldsets + (
608 (None, {
609 'fields': ('code', 'nom', ),
610 }),
611 )
6e7c919b 612
babf71ec 613class TauxChangeAdmin(admin.ModelAdmin):
24475cf1
OL
614 list_display = ('taux', 'devise', 'annee', )
615 list_filter = ('devise', )
dcbadfad
OL
616 fieldsets = AUFMetadataAdminMixin.fieldsets + (
617 (None, {
618 'fields': ('taux', 'devise', 'annee', ),
619 }),
620 )
6e7c919b 621
6e7c919b 622class TypeContratAdmin(admin.ModelAdmin):
babf71ec 623 inlines = (ContratInline,)
7376afeb
PP
624 fieldsets = AUFMetadataAdminMixin.fieldsets + (
625 (None, {
626 'fields': ('nom', 'nom_long', ),
627 }),
628 )
6e7c919b 629
6e7c919b 630
240893cb 631class TypePosteAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
d8d7985b 632 search_fields = ('nom', 'nom_feminin', )
52e05b08
OL
633 list_display = ('nom', 'famille_emploi', )
634 list_filter = ('famille_emploi', )
240893cb
OL
635 fieldsets = AUFMetadataAdminMixin.fieldsets + (
636 (None, {
637 'fields': ('nom', 'nom_feminin', 'is_responsable', 'famille_emploi', )
638 }),
639 )
6e7c919b 640
6e7c919b 641
3f486b41 642class TypeRemunerationAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
f7efd29a 643 list_display = ('nom', 'type_paiement', 'nature_remuneration', )
3f486b41
OL
644 #inlines = (RemunerationROInline,) utilité?
645 fieldsets = AUFMetadataAdminMixin.fieldsets + (
646 (None, {
647 'fields': ('nom', 'type_paiement', 'nature_remuneration', )
648 }),
649 )
6e7c919b 650
6e7c919b 651
3f486b41
OL
652class TypeRevalorisationAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
653 #inlines = (RemunerationROInline,) utilité?
654 fieldsets = AUFMetadataAdminMixin.fieldsets + (
655 (None, {
656 'fields': ('nom', )
657 }),
658 )
6e7c919b 659
6e7c919b 660
84fc088b 661class ValeurPointAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
701f3bea 662 list_display = ('_devise_code', '_devise_nom', 'annee', 'valeur', )
84fc088b
OL
663 fieldsets = AUFMetadataAdminMixin.fieldsets + (
664 (None, {
665 'fields': ('valeur', 'devise', 'implantation', 'annee', )
666 }),
667 )
701f3bea
OL
668
669 def _devise_code(self, obj):
670 return obj.devise.code
671 _devise_code.short_description = "Code de la devise"
672
673 def _devise_nom(self, obj):
674 return obj.devise.nom
675 _devise_nom.short_description = "Nom de la devise"
49c98347
PP
676
677
678def calc_remun(dossier):
679 thisyear = datetime.date.today().year
680 thisyearfilter = Q(date_debut__year=thisyear) | Q(date_fin__year=thisyear)
681
682 remunnow = dossier.rh_remuneration_remunerations.filter(thisyearfilter)
683
684 remun_sum = 0
685 remun_sum_euro = 0
686 sums = defaultdict(int)
687 sums_euro = defaultdict(int)
688 for r in remunnow:
689 nature = r.type.nature_remuneration
690 sums[nature] += r.montant
691 sums_euro[nature] += r.montant_euro()
692 remun_sum += r.montant
693 remun_sum_euro += r.montant_euro()
694
695 remun = {}
696 sums = dict(sums)
697 for n, s in sums.iteritems():
698 remun[n] = [sums[n], sums_euro[n]]
699
700 return remun, remun_sum, remun_sum_euro