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