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