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