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