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