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