add permissions RH
[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
OL
268 list_display = ('_id', '_employe', '_actif', '_poste', 'date_debut', 'date_fin', 'date_modification')
269 list_filter = ('poste__implantation__region', 'poste__implantation', 'date_debut', 'date_fin', )
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',
297 'date_fin__year',
298 'date_fin__month',
299 'date_fin__day',
300 'date_debut__year',
301 'date_debut__month',
302 'date_debut__day',
303 ):
387ab827
OL
304 return True
305
150d83ec
OL
306 def _id(self, d):
307 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>""" % \
308 (reverse('dossier_apercu', args=(d.id,)),
309 d.id,
310 reverse('admin:rh_dossier_change', args=(d.id,)),
311 settings.MEDIA_URL,
312 )
313 return link
314 _id.allow_tags = True
315 _id.short_description = u'Numéro de dossier'
316 _id.admin_order_field = 'id'
317
318
49449367
OL
319 def _actif(self, dossier):
320 if dossier.employe.actif:
321 html = """<img alt="True" src="%simg/admin/icon-yes.gif">"""
322 else:
323 html = """<img alt="False" src="%simg/admin/icon-no.gif">"""
324 return html % settings.ADMIN_MEDIA_PREFIX
150d83ec 325 _actif.allow_tags = True
49449367
OL
326 _actif.short_description = u'Employé actif'
327 _actif.admin_order_field = 'employe__actif'
387ab827 328
54d04eed 329 def _poste(self, dossier):
150d83ec
OL
330 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>""" % \
331 (reverse('poste_apercu', args=(dossier.poste.id,)),
332 dossier.poste,
333 reverse('admin:rh_poste_change', args=(dossier.poste.id,)),
334 settings.MEDIA_URL,
335 )
336 return link
337 _poste.allow_tags = True
54d04eed 338 _poste.short_description = u'Poste'
d9836879 339 _poste.admin_order_field = 'poste__nom'
54d04eed 340
150d83ec
OL
341 def _employe(self, obj):
342 employe = obj.employe
343 view_link = reverse('employe_apercu', args=(employe.id,))
344 edit_link = reverse('admin:rh_employe_change', args=(employe.id,))
345 return u"""<a onclick="return showAddAnotherPopup(this);" href='%s'>[%s] %s %s</a>
346 <a href="%s" title="Modifier l'employé"><img src="%simg/user_edit.png" /></a>""" % \
347 (view_link, employe.id, employe.nom.upper(), employe.prenom.title(), edit_link, settings.MEDIA_URL,)
348 _employe.allow_tags = True
349 _employe.short_description = u"Employé ([code] NOM Prénom)"
350 _employe.admin_order_field = "employe__nom"
d9836879 351
1f2979b8
OL
352 def save_formset(self, request, form, formset, change):
353 instances = formset.save(commit=False)
354 for instance in instances:
355 if instance.__class__ == rh.DossierCommentaire:
356 instance.owner = request.user
357 instance.save()
6e7c919b 358
8d3e2fff 359
6e7c919b
NC
360class DossierPieceAdmin(admin.ModelAdmin):
361 pass
362
54d04eed 363
6e7c919b
NC
364class DossierCommentaireAdmin(admin.ModelAdmin):
365 pass
366
54d04eed 367
cb527994
PP
368class EmployeAdminForm(forms.ModelForm):
369 class Meta:
370 model = rh.Employe
371
372 def __init__(self, *args, **kwargs):
373 super(EmployeAdminForm, self).__init__(*args, **kwargs)
52688246 374 self.fields['date_naissance'].widget = forms.widgets.DateInput()
cb527994
PP
375
376
aff1a4c6 377class EmployeAdmin(AUFMetadataAdminMixin, ProtectRegionMixin, admin.ModelAdmin):
7ffc5aa4 378 alphabet_filter = 'nom'
2a333057 379 DEFAULT_ALPHABET = u'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
64721a83 380 search_fields = ('id', 'nom', 'prenom', 'nom_affichage', )
49449367
OL
381 ordering = ('nom', )
382 actions = ('desactiver', )
cb527994 383 form = EmployeAdminForm
4a1f2ece 384 list_display = ('_nom', '_dossiers', 'date_modification', 'user_modification',)
2580a2d9 385 list_filter = ('dossiers__poste__implantation__region', 'dossiers__poste__implantation', 'actif', )
babf71ec
NC
386 inlines = (AyantDroitInline,
387 DossierROInline,
388 EmployePieceInline,
389 EmployeCommentaireInline)
64721a83 390 fieldsets = AUFMetadataAdminMixin.fieldsets + (
cf786fb2 391 ('Identification', {
e35610f5 392 'fields': (('nom', 'prenom'), ('nom_affichage', 'genre'), 'nationalite', 'date_naissance', )
cf786fb2
OL
393 }),
394 ('Informations personnelles', {
395 'fields': ('situation_famille', 'date_entree', )
396 }),
397 ('Coordonnées', {
e35610f5 398 'fields': (('tel_domicile', 'tel_cellulaire'), ('adresse', 'ville'), ('code_postal', 'province'), 'pays', )
cf786fb2
OL
399 }),
400 )
babf71ec 401
4a1f2ece
OL
402 def _nom(self, obj):
403 view_link = reverse('employe_apercu', args=(obj.id,))
404 edit_link = reverse('admin:rh_employe_change', args=(obj.id,))
405 return u"""<a onclick="return showAddAnotherPopup(this);" href='%s'>[%s] %s %s</a>
406 <a href="%s" title="Modifier l'employé"><img src="%simg/user_edit.png" /></a>""" % \
407 (view_link, obj.id, obj.nom.upper(), obj.prenom.title(), edit_link, settings.MEDIA_URL,)
408 _nom.allow_tags = True
409 _nom.short_description = u"Employé ([code] NOM Prénom)"
410 _nom.admin_order_field = "nom"
411
790b9793
OL
412 def _dossiers(self, obj):
413 l = []
414 for d in obj.dossiers.all().order_by('-date_debut'):
3ebc0952
OL
415 style = ""
416 if d.date_fin is not None:
417 style = "color: grey";
4a1f2ece 418 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
419 (style,
420 reverse('dossier_apercu', args=(d.id,)),
790b9793 421 d.date_debut.year,
4a1f2ece
OL
422 d.poste,
423 reverse('admin:rh_dossier_change', args=(d.id,)),
424 settings.MEDIA_URL,
425 )
790b9793
OL
426 l.append(link)
427 return "<ul>%s</ul>" % "\n".join(l)
428 _dossiers.allow_tags = True
429
64721a83 430 def queryset(self, request):
7eb1ab09 431 qs = super(EmployeAdmin, self).queryset(request)
2a333057 432 return qs.filter(actif=True).select_related(depth=1).order_by('nom')
64721a83 433
cf786fb2
OL
434 def save_formset(self, request, form, formset, change):
435 instances = formset.save(commit=False)
436 for instance in instances:
437 if instance.__class__ == rh.EmployeCommentaire:
438 instance.owner = request.user
439 instance.save()
babf71ec 440
2d5533ac
PP
441
442
babf71ec 443class EmployeCommentaireAdmin(admin.ModelAdmin):
6e7c919b
NC
444 pass
445
54d04eed 446
babf71ec 447class EmployePieceAdmin(admin.ModelAdmin):
6e7c919b
NC
448 pass
449
54d04eed 450
6e7c919b 451class EvenementAdmin(admin.ModelAdmin):
babf71ec 452 inlines = (EvenementRemunerationInline,)
6e7c919b 453
54d04eed 454
6e7c919b
NC
455class EvenementRemunerationAdmin(admin.ModelAdmin):
456 pass
457
54d04eed 458
26dacccc 459class FamilleEmploiAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
babf71ec 460 inlines = (TypePosteInline,)
26dacccc
OL
461 fieldsets = AUFMetadataAdminMixin.fieldsets + (
462 (None, {
463 'fields': ('nom', )
464 }),
465 )
6e7c919b 466
54d04eed 467
aff1a4c6 468class OrganismeBstgAdmin(AUFMetadataAdminMixin, ProtectRegionMixin, admin.ModelAdmin):
d8d7985b 469 search_fields = ('nom', )
1c8856ef 470 list_display = ('nom', 'type', 'pays', )
babf71ec 471 inlines = (DossierROInline,)
43f5653a
OL
472 fieldsets = AUFMetadataAdminMixin.fieldsets + (
473 (None, {
474 'fields': ('nom', 'type', 'pays', )
475 }),
476 )
6e7c919b 477
54d04eed 478
aff1a4c6 479class PosteAdmin(AUFMetadataAdminMixin, ProtectRegionMixin, admin.ModelAdmin):
387ab827 480 alphabet_filter = 'nom'
23102192
DB
481 search_fields = ('nom',
482 'implantation__code',
483 'implantation__nom',
484 'implantation__region__code',
485 'implantation__region__nom',
486 )
150d83ec
OL
487 list_display = (
488 '_nom',
23102192
DB
489 '_occupe_par',
490 'implantation',
491 'service',
492 'type_poste',
493 'date_debut',
494 'date_fin',
495 'date_modification',
496 'user_modification',
497 )
498 list_filter = ('service',
499 'implantation__region',
500 'implantation__adresse_physique_pays',
501 'implantation',
502 )
d2cf315a 503 fieldsets = AUFMetadataAdminMixin.fieldsets + (
6e7c919b 504 (None, {
4497b3cb 505 'fields': (('nom', 'nom_feminin'), 'implantation', 'type_poste',
6e7c919b
NC
506 'service', 'responsable')
507 }),
508 ('Contrat', {
4497b3cb 509 'fields': (('regime_travail', 'regime_travail_nb_heure_semaine'), )
6e7c919b
NC
510 }),
511 ('Recrutement', {
4497b3cb 512 'fields': (('local', 'expatrie', 'mise_a_disposition', 'appel'),)
6e7c919b
NC
513 }),
514 ('Rémunération', {
4497b3cb
PP
515 'fields': (('classement_min', 'classement_max'),
516 ('valeur_point_min', 'valeur_point_max'),
517 ('devise_min', 'devise_max'),
518 ('salaire_min', 'salaire_max'),
519 ('indemn_min', 'indemn_max'),
520 ('autre_min', 'autre_max'))
6e7c919b
NC
521 }),
522 ('Comparatifs de rémunération', {
4497b3cb
PP
523 'fields': ('devise_comparaison',
524 ('comp_locale_min', 'comp_locale_max'),
525 ('comp_universite_min', 'comp_universite_max'),
526 ('comp_fonctionpub_min', 'comp_fonctionpub_max'),
527 ('comp_ong_min', 'comp_ong_max'),
528 ('comp_autre_min', 'comp_autre_max'))
6e7c919b
NC
529 }),
530 ('Justification', {
531 'fields': ('justification',)
532 }),
533 ('Autres Metadata', {
4497b3cb 534 'fields': ('date_validation', ('date_debut', 'date_fin'))
6e7c919b
NC
535 }),
536 )
537
babf71ec
NC
538 inlines = (PosteFinancementInline,
539 PostePieceInline,
70561dc2
OL
540 DossierROInline,
541 PosteCommentaireInline, )
6e7c919b 542
150d83ec
OL
543 def _nom(self, poste):
544 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>""" % \
545 (reverse('poste_apercu', args=(poste.id,)),
546 poste.nom,
547 reverse('admin:rh_poste_change', args=(poste.id,)),
548 settings.MEDIA_URL,
549 )
550 return link
551 _nom.allow_tags = True
552 _nom.short_description = u'Nom'
553 _nom.admin_order_field = 'nom'
554
23102192
DB
555 def _occupe_par(self, obj):
556 """Formatte la méthode Poste.occupe_par() pour l'admin"""
557 output = "VACANT"
558 employes = obj.occupe_par()
559 if employes:
560 l = []
561 for e in employes:
562 link = "<a href='%s'>%s</a>" % \
563 (reverse('admin:rh_employe_change', args=(e.id,)),
564 e)
565 l.append(link)
566 output = "\n<br />".join(l)
567 return output
568 _occupe_par.allow_tags = True
569 _occupe_par.short_description = "Occupé par"
570
70561dc2
OL
571 def save_formset(self, request, form, formset, change):
572 instances = formset.save(commit=False)
573 for instance in instances:
574 if instance.__class__ == rh.PosteCommentaire:
575 instance.owner = request.user
576 instance.save()
577 formset.save_m2m()
6e7c919b 578
aff1a4c6 579
6e7c919b
NC
580class PosteCommentaireAdmin(admin.ModelAdmin):
581 pass
582
6e7c919b 583
babf71ec 584class PosteFinancementAdmin(admin.ModelAdmin):
6e7c919b
NC
585 pass
586
6e7c919b 587
babf71ec 588class PostePieceAdmin(admin.ModelAdmin):
6e7c919b
NC
589 pass
590
6e7c919b 591
babf71ec 592class RemunerationAdmin(admin.ModelAdmin):
6e7c919b
NC
593 pass
594
6e7c919b 595
1eede0db
OL
596class ResponsableImplantationAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
597 fieldsets = AUFMetadataAdminMixin.fieldsets + (
598 (None, {
599 'fields': ('employe', 'implantation', ),
600 }),
601 )
602
6e7c919b 603
43f5653a
OL
604class ServiceAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
605 list_display = ('nom', 'actif', )
606 fieldsets = AUFMetadataAdminMixin.fieldsets + (
607 (None, {
608 'fields': ('nom', ),
609 }),
610 )
6e7c919b 611
43f5653a
OL
612class StatutAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
613 fieldsets = AUFMetadataAdminMixin.fieldsets + (
614 (None, {
615 'fields': ('code', 'nom', ),
616 }),
617 )
6e7c919b 618
babf71ec 619class TauxChangeAdmin(admin.ModelAdmin):
24475cf1
OL
620 list_display = ('taux', 'devise', 'annee', )
621 list_filter = ('devise', )
dcbadfad
OL
622 fieldsets = AUFMetadataAdminMixin.fieldsets + (
623 (None, {
624 'fields': ('taux', 'devise', 'annee', ),
625 }),
626 )
6e7c919b 627
6e7c919b 628class TypeContratAdmin(admin.ModelAdmin):
babf71ec 629 inlines = (ContratInline,)
7376afeb
PP
630 fieldsets = AUFMetadataAdminMixin.fieldsets + (
631 (None, {
632 'fields': ('nom', 'nom_long', ),
633 }),
634 )
6e7c919b 635
6e7c919b 636
240893cb 637class TypePosteAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
d8d7985b 638 search_fields = ('nom', 'nom_feminin', )
52e05b08
OL
639 list_display = ('nom', 'famille_emploi', )
640 list_filter = ('famille_emploi', )
240893cb
OL
641 fieldsets = AUFMetadataAdminMixin.fieldsets + (
642 (None, {
643 'fields': ('nom', 'nom_feminin', 'is_responsable', 'famille_emploi', )
644 }),
645 )
6e7c919b 646
6e7c919b 647
3f486b41 648class TypeRemunerationAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
f7efd29a 649 list_display = ('nom', 'type_paiement', 'nature_remuneration', )
3f486b41
OL
650 #inlines = (RemunerationROInline,) utilité?
651 fieldsets = AUFMetadataAdminMixin.fieldsets + (
652 (None, {
653 'fields': ('nom', 'type_paiement', 'nature_remuneration', )
654 }),
655 )
6e7c919b 656
6e7c919b 657
3f486b41
OL
658class TypeRevalorisationAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
659 #inlines = (RemunerationROInline,) utilité?
660 fieldsets = AUFMetadataAdminMixin.fieldsets + (
661 (None, {
662 'fields': ('nom', )
663 }),
664 )
6e7c919b 665
6e7c919b 666
84fc088b 667class ValeurPointAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
701f3bea 668 list_display = ('_devise_code', '_devise_nom', 'annee', 'valeur', )
84fc088b
OL
669 fieldsets = AUFMetadataAdminMixin.fieldsets + (
670 (None, {
671 'fields': ('valeur', 'devise', 'implantation', 'annee', )
672 }),
673 )
701f3bea
OL
674
675 def _devise_code(self, obj):
676 return obj.devise.code
677 _devise_code.short_description = "Code de la devise"
678
679 def _devise_nom(self, obj):
680 return obj.devise.nom
681 _devise_nom.short_description = "Nom de la devise"
49c98347
PP
682
683
684def calc_remun(dossier):
685 thisyear = datetime.date.today().year
686 thisyearfilter = Q(date_debut__year=thisyear) | Q(date_fin__year=thisyear)
687
688 remunnow = dossier.rh_remuneration_remunerations.filter(thisyearfilter)
689
690 remun_sum = 0
691 remun_sum_euro = 0
692 sums = defaultdict(int)
693 sums_euro = defaultdict(int)
694 for r in remunnow:
695 nature = r.type.nature_remuneration
696 sums[nature] += r.montant
697 sums_euro[nature] += r.montant_euro()
698 remun_sum += r.montant
699 remun_sum_euro += r.montant_euro()
700
701 remun = {}
702 sums = dict(sums)
703 for n, s in sums.iteritems():
704 remun[n] = [sums[n], sums_euro[n]]
705
706 return remun, remun_sum, remun_sum_euro