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