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