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