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