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