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