Total des remun trans-dossiers
[auf_rh_dae.git] / project / rh / lib.py
CommitLineData
6e7c919b
NC
1# -*- encoding: utf-8 -*-
2
8d3e2fff
PP
3from collections import defaultdict
4import datetime
5
babf71ec 6from django.db import models
6e7c919b 7from django.contrib import admin
49449367 8from django.conf import settings
aff1a4c6 9from django.db.models import Q
d6985a3a 10from auf.django.metadata.admin import AUFMetadataAdminMixin, AUFMetadataInlineAdminMixin, AUF_METADATA_READONLY_FIELDS
babf71ec 11from project.rh import models as rh
84cbb4c5 12from forms import DossierForm, ContratForm
aff1a4c6
PP
13from dae.utils import get_employe_from_user
14
15
6318ebea
PP
16# Override of the InlineModelAdmin to support the link in the tabular inline
17class LinkedInline(admin.options.InlineModelAdmin):
18 template = "admin/linked.html"
19 admin_model_path = None
20
21 def __init__(self, *args):
22 super(LinkedInline, self).__init__(*args)
23 if self.admin_model_path is None:
24 self.admin_model_path = self.model.__name__.lower()
25
26
aff1a4c6
PP
27class ProtectRegionMixin(object):
28
29 def queryset(self, request):
30 qs = super(ProtectRegionMixin, self).queryset(request)
31
32 if request.user.is_superuser:
33 return qs
34
35 employe = get_employe_from_user(request.user)
36
37 q = Q(**{self.model.prefix_implantation: employe.implantation.region})
38 qs = qs.filter(q).distinct()
39 return qs
40
41 def has_change_permission(self, request, obj=None):
42 if request.user.is_superuser:
43 return True
44
45 if obj:
46 employe = get_employe_from_user(request.user)
47 if employe.implantation.region in obj.get_regions():
48 return True
49 else:
50 return False
51
52 return True
53
6e7c919b 54
d6985a3a 55# Inlines
6e7c919b 56
d6985a3a
OL
57class ReadOnlyInlineMixin(object):
58 def get_readonly_fields(self, request, obj=None):
59 return [f.name for f in self.model._meta.fields if f.name not in AUF_METADATA_READONLY_FIELDS]
6e7c919b
NC
60
61
51ab4c2c 62class AyantDroitInline(AUFMetadataInlineAdminMixin, admin.StackedInline):
babf71ec 63 model = models.Model # à remplacer dans admin.py
51ab4c2c 64 extra = 0
54d04eed 65
972f50e4
PP
66 fieldsets = (
67 (None, {
68 'fields': (('nom', 'prenom'), ('nom_affichage', 'genre'), 'nationalite', 'date_naissance', 'lien_parente', )
69 }),
70 )
71
d6985a3a
OL
72
73class AyantDroitCommentaireInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
cf786fb2 74 readonly_fields = ('owner', )
babf71ec 75 model = models.Model # à remplacer dans admin.py
cf786fb2 76 extra = 1
6e7c919b 77
54d04eed 78
d6985a3a 79class ContratInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
84cbb4c5 80 form = ContratForm
babf71ec 81 model = models.Model # à remplacer dans admin.py
1f2979b8 82 extra = 1
babf71ec
NC
83
84
6318ebea 85class DossierROInline(ReadOnlyInlineMixin, LinkedInline):
d6985a3a 86 exclude = AUF_METADATA_READONLY_FIELDS
babf71ec 87 model = models.Model # à remplacer dans admin.py
54773196 88 extra = 0
babf71ec 89
d6985a3a
OL
90
91class DossierCommentaireInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
1f2979b8 92 readonly_fields = ('owner', )
babf71ec 93 model = models.Model # à remplacer dans admin.py
1f2979b8 94 extra = 1
babf71ec 95
d6985a3a 96
babf71ec
NC
97class DossierPieceInline(admin.TabularInline):
98 model = models.Model # à remplacer dans admin.py
988af3fb 99 extra = 4
babf71ec
NC
100
101
102class EmployeInline(admin.TabularInline):
103 model = models.Model # à remplacer dans admin.py
104
d6985a3a 105class EmployeCommentaireInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
cf786fb2 106 readonly_fields = ('owner', )
babf71ec 107 model = models.Model # à remplacer dans admin.py
cf786fb2 108 extra = 1
babf71ec
NC
109
110
111class EmployePieceInline(admin.TabularInline):
112 model = models.Model # à remplacer dans admin.py
988af3fb 113 extra = 4
babf71ec
NC
114
115
d6985a3a 116class EvenementInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
babf71ec 117 model = models.Model # à remplacer dans admin.py
1f2979b8 118 extra = 1
babf71ec
NC
119
120
d6985a3a 121class EvenementRemunerationInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
babf71ec 122 model = models.Model # à remplacer dans admin.py
1f2979b8 123 extra = 1
babf71ec
NC
124
125
d6985a3a 126class PosteCommentaireInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
70561dc2 127 readonly_fields = ('owner', )
babf71ec 128 model = models.Model # à remplacer dans admin.py
70561dc2 129 extra = 1
babf71ec
NC
130
131
132class PosteFinancementInline(admin.TabularInline):
133 model = models.Model # à remplacer dans admin.py
134
135
136class PostePieceInline(admin.TabularInline):
137 model = models.Model # à remplacer dans admin.py
138
139
d6985a3a 140class RemunerationInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
babf71ec 141 model = models.Model # à remplacer dans admin.py
1f2979b8 142 extra = 1
babf71ec
NC
143
144
d6985a3a 145class RemunerationROInline(ReadOnlyInlineMixin, RemunerationInline):
6e7c919b
NC
146 pass
147
54d04eed 148
26dacccc 149class TypePosteInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
babf71ec
NC
150 model = models.Model # à remplacer dans admin.py
151
152
153# Admins
154
aff1a4c6 155class AyantDroitAdmin(AUFMetadataAdminMixin, ProtectRegionMixin, admin.ModelAdmin):
cf786fb2
OL
156 """
157 L'ajout d'un nouvel ayantdroit se fait dans l'admin de l'employé.
158 """
387ab827 159 alphabet_filter = 'nom'
cf786fb2 160 search_fields = ('nom', 'prenom', 'employe__nom', 'employe__prenom', )
1a89b1f3 161 list_display = ('_employe', 'lien_parente', '_ayantdroit', )
babf71ec 162 inlines = (AyantDroitCommentaireInline,)
d6985a3a
OL
163 readonly_fields = AUFMetadataAdminMixin.readonly_fields + ('employe',)
164 fieldsets = AUFMetadataAdminMixin.fieldsets + (
cf786fb2 165 ("Lien avec l'employé", {
76e26dfc 166 'fields': (('employe', 'lien_parente'), )
cf786fb2
OL
167 }),
168
169 ('Identification', {
76e26dfc 170 'fields': (('nom', 'prenom'), ('nom_affichage', 'genre'), 'nationalite', 'date_naissance', )
cf786fb2
OL
171 }),
172 )
173
174 def save_formset(self, request, form, formset, change):
175 instances = formset.save(commit=False)
176 for instance in instances:
177 if instance.__class__ == rh.AyantDroitCommentaire:
178 instance.owner = request.user
179 instance.save()
cf786fb2
OL
180
181 def _ayantdroit(self, obj):
182 return unicode(obj)
183 _ayantdroit.short_description = u'Ayant droit'
babf71ec 184
cf786fb2
OL
185 def _employe(self, obj):
186 return unicode(obj.employe)
187 _employe.short_description = u'Employé'
188
189 def has_add_permission(self, request):
190 return False
babf71ec
NC
191
192class AyantDroitCommentaireAdmin(admin.ModelAdmin):
6e7c919b
NC
193 pass
194
54d04eed 195
324bf312
OL
196class ClassementAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
197 fieldsets = AUFMetadataAdminMixin.fieldsets + (
198 (None, {
199 'fields': ('type', 'echelon', 'degre', 'coefficient', )
200 }),
201 )
202
6e7c919b 203
6e7c919b
NC
204class CommentaireAdmin(admin.ModelAdmin):
205 pass
206
207
84cbb4c5
OL
208#class ContratAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
209# form = ContratForm
210# alphabet_filter = 'dossier__employe__nom'
211# search_fields = ('dossier__employe__nom', 'dossier__employe__prenom', 'dossier__poste__nom', 'dossier__poste__nom_feminin', )
212# list_display = ('id', '_employe', '_poste', 'date_debut', 'date_fin', '_implantation', )
213# fieldsets = AUFMetadataAdminMixin.fieldsets + (
214# (None, {
215# 'fields': ('dossier', 'type_contrat', 'date_debut', 'date_fin', )
216# }),
217# )
218#
219# def lookup_allowed(self, key, value):
220# if key in ('dossier__employe__nom__istartswith', ):
221# return True
222#
223# def _employe(self, obj):
224# return unicode(obj.dossier.employe)
225# _employe.short_description = "Employé"
226#
227# def _poste(self, obj):
228# return obj.dossier.poste.nom
229# _poste.short_description = "Poste"
230#
231# def _implantation(self, obj):
232# return obj.dossier.poste.implantation
233# _poste.short_description = "Implantation"
54d04eed 234
84fc088b
OL
235class DeviseAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
236 fieldsets = AUFMetadataAdminMixin.fieldsets + (
237 (None, {
238 'fields': ('code', 'nom', ),
239 }),
240 )
6e7c919b 241
54d04eed 242
aff1a4c6 243class DossierAdmin(AUFMetadataAdminMixin, ProtectRegionMixin, admin.ModelAdmin,):
84cbb4c5 244 form = DossierForm
387ab827 245 alphabet_filter = 'employe__nom'
d8d7985b 246 search_fields = ('employe__nom', 'employe__prenom', 'poste__nom', 'poste__nom_feminin')
55ca522c 247 list_display = ('_employe', '_poste', 'date_debut', 'date_fin', 'date_modification', '_actif')
1f2979b8 248 inlines = (DossierPieceInline, ContratInline,
cf786fb2
OL
249 RemunerationInline,
250 #EvenementInline,
251 DossierCommentaireInline,
1f2979b8 252 )
d6985a3a 253 fieldsets = AUFMetadataAdminMixin.fieldsets + (
5961a2c9 254 (None, {
7ac30609 255 'fields': ('employe', 'poste', 'statut', 'organisme_bstg',)
1f2979b8
OL
256 }),
257 ('Recrutement', {
7c182958 258 'fields': ('statut_residence', 'remplacement', 'remplacement_de', )
1f2979b8
OL
259 }),
260 ('Rémunération', {
cb962802 261 'fields': ('classement', ('regime_travail', 'regime_travail_nb_heure_semaine'),)
1f2979b8
OL
262 }),
263 ('Occupation du Poste par cet Employe', {
cb962802 264 'fields': (('date_debut', 'date_fin'), )
1f2979b8
OL
265 }),
266 )
54d04eed 267
7ac30609
PP
268 add_form_template = 'admin/change_form.html'
269
7c182958
PP
270 class Media:
271 js = ('js/dossier.js',)
272
387ab827 273 def lookup_allowed(self, key, value):
49449367 274 if key in ('employe__nom__istartswith', 'actif__exact', ):
387ab827
OL
275 return True
276
49449367
OL
277 def _actif(self, dossier):
278 if dossier.employe.actif:
279 html = """<img alt="True" src="%simg/admin/icon-yes.gif">"""
280 else:
281 html = """<img alt="False" src="%simg/admin/icon-no.gif">"""
282 return html % settings.ADMIN_MEDIA_PREFIX
283 _actif.allow_tags = u'Employé actif'
284 _actif.short_description = u'Employé actif'
285 _actif.admin_order_field = 'employe__actif'
387ab827 286
54d04eed
NC
287 def _poste(self, dossier):
288 return unicode(dossier.poste.nom)
289 _poste.short_description = u'Poste'
d9836879 290 _poste.admin_order_field = 'poste__nom'
54d04eed
NC
291
292 def _employe(self, dossier):
293 return unicode(dossier.employe)
294 _employe.short_description = u'Employé'
d9836879
OL
295 _employe.admin_order_field = 'employe__nom'
296
1f2979b8
OL
297 def save_formset(self, request, form, formset, change):
298 instances = formset.save(commit=False)
299 for instance in instances:
300 if instance.__class__ == rh.DossierCommentaire:
301 instance.owner = request.user
302 instance.save()
6e7c919b 303
8d3e2fff 304 def render_change_form(self, request, context, *args, **kwargs):
49c98347 305 obj = kwargs.get('obj', None)
8d3e2fff 306
49c98347
PP
307 if not obj:
308 return super(DossierAdmin, self).render_change_form(request, context, *args, **kwargs)
8d3e2fff 309
8d3e2fff 310
49c98347 311 remun, remun_sum, remun_sum_euro = calc_remun(obj)
8d3e2fff
PP
312
313 extra = {
314 'remun': remun,
315 'remun_sum': remun_sum,
316 'remun_sum_euro': remun_sum_euro,
5961a2c9
PP
317 'employe': obj.employe,
318 'poste_nom': obj.poste.nom,
319 'poste_service': obj.poste.service,
320 'poste_implantation': obj.poste.implantation,
8d3e2fff
PP
321 }
322
323 context.update(extra)
324
325 return super(DossierAdmin, self).render_change_form(request, context, *args, **kwargs)
326
327
6e7c919b
NC
328class DossierPieceAdmin(admin.ModelAdmin):
329 pass
330
54d04eed 331
6e7c919b
NC
332class DossierCommentaireAdmin(admin.ModelAdmin):
333 pass
334
54d04eed 335
aff1a4c6 336class EmployeAdmin(AUFMetadataAdminMixin, ProtectRegionMixin, admin.ModelAdmin):
7ffc5aa4 337 alphabet_filter = 'nom'
49449367
OL
338 search_fields = ('id', 'nom', 'prenom', 'nom_affichage', 'actif', )
339 list_filter = ('actif', )
340 ordering = ('nom', )
341 actions = ('desactiver', )
54773196
PP
342 list_display = ('id', 'nom', 'prenom', 'actif', )
343 list_display_links = ('id', 'nom',)
babf71ec
NC
344 inlines = (AyantDroitInline,
345 DossierROInline,
346 EmployePieceInline,
347 EmployeCommentaireInline)
d6985a3a 348 fieldsets = AUFMetadataAdminMixin.fieldsets + (
cf786fb2 349 ('Identification', {
e35610f5 350 'fields': (('nom', 'prenom'), ('nom_affichage', 'genre'), 'nationalite', 'date_naissance', )
cf786fb2
OL
351 }),
352 ('Informations personnelles', {
353 'fields': ('situation_famille', 'date_entree', )
354 }),
355 ('Coordonnées', {
e35610f5 356 'fields': (('tel_domicile', 'tel_cellulaire'), ('adresse', 'ville'), ('code_postal', 'province'), 'pays', )
cf786fb2
OL
357 }),
358 )
babf71ec 359
2d5533ac
PP
360 add_form_template = 'admin/change_form.html'
361
cf786fb2
OL
362 def save_formset(self, request, form, formset, change):
363 instances = formset.save(commit=False)
364 for instance in instances:
365 if instance.__class__ == rh.EmployeCommentaire:
366 instance.owner = request.user
367 instance.save()
babf71ec 368
2d5533ac
PP
369 def render_change_form(self, request, context, *args, **kwargs):
370 obj = kwargs.get('obj', None)
371
372 if not obj:
373 return super(EmployeAdmin, self).render_change_form(request, context, *args, **kwargs)
374
375 remun = {}
376 remun_sum = 0
377 remun_sum_euro = 0
378 dossiers = obj.dossiers.all()
379
380 for dossier in dossiers:
381 this_remun, this_remun_sum, this_remun_sum_euro = calc_remun(dossier)
382
383 for item in this_remun:
384 if item not in remun:
385 remun[item] = this_remun[item]
386 else:
387 remun[item][0] += this_remun[item][0]
388 remun[item][1] += this_remun[item][1]
389
390 remun_sum += this_remun_sum
391 remun_sum_euro += this_remun_sum_euro
392
393 extra = {
394 'remun': remun,
395 'remun_sum': remun_sum,
396 'remun_sum_euro': remun_sum_euro,
397 }
398
399 context.update(extra)
400
401 return super(EmployeAdmin, self).render_change_form(request, context, *args, **kwargs)
402
403
babf71ec 404class EmployeCommentaireAdmin(admin.ModelAdmin):
6e7c919b
NC
405 pass
406
54d04eed 407
babf71ec 408class EmployePieceAdmin(admin.ModelAdmin):
6e7c919b
NC
409 pass
410
54d04eed 411
6e7c919b 412class EvenementAdmin(admin.ModelAdmin):
babf71ec 413 inlines = (EvenementRemunerationInline,)
6e7c919b 414
54d04eed 415
6e7c919b
NC
416class EvenementRemunerationAdmin(admin.ModelAdmin):
417 pass
418
54d04eed 419
26dacccc 420class FamilleEmploiAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
babf71ec 421 inlines = (TypePosteInline,)
26dacccc
OL
422 fieldsets = AUFMetadataAdminMixin.fieldsets + (
423 (None, {
424 'fields': ('nom', )
425 }),
426 )
6e7c919b 427
54d04eed 428
aff1a4c6 429class OrganismeBstgAdmin(AUFMetadataAdminMixin, ProtectRegionMixin, admin.ModelAdmin):
d8d7985b 430 search_fields = ('nom', )
1c8856ef 431 list_display = ('nom', 'type', 'pays', )
babf71ec 432 inlines = (DossierROInline,)
43f5653a
OL
433 fieldsets = AUFMetadataAdminMixin.fieldsets + (
434 (None, {
435 'fields': ('nom', 'type', 'pays', )
436 }),
437 )
6e7c919b 438
54d04eed 439
aff1a4c6 440class PosteAdmin(AUFMetadataAdminMixin, ProtectRegionMixin, admin.ModelAdmin):
387ab827 441 alphabet_filter = 'nom'
70561dc2
OL
442 search_fields = ('nom', 'implantation__code', 'implantation__nom', 'implantation__region__code', 'implantation__region__nom', )
443 list_display = ('nom', 'implantation', 'service', 'type_poste', 'date_debut', 'date_fin', )
d2cf315a 444 fieldsets = AUFMetadataAdminMixin.fieldsets + (
6e7c919b 445 (None, {
4497b3cb 446 'fields': (('nom', 'nom_feminin'), 'implantation', 'type_poste',
6e7c919b
NC
447 'service', 'responsable')
448 }),
449 ('Contrat', {
4497b3cb 450 'fields': (('regime_travail', 'regime_travail_nb_heure_semaine'), )
6e7c919b
NC
451 }),
452 ('Recrutement', {
4497b3cb 453 'fields': (('local', 'expatrie', 'mise_a_disposition', 'appel'),)
6e7c919b
NC
454 }),
455 ('Rémunération', {
4497b3cb
PP
456 'fields': (('classement_min', 'classement_max'),
457 ('valeur_point_min', 'valeur_point_max'),
458 ('devise_min', 'devise_max'),
459 ('salaire_min', 'salaire_max'),
460 ('indemn_min', 'indemn_max'),
461 ('autre_min', 'autre_max'))
6e7c919b
NC
462 }),
463 ('Comparatifs de rémunération', {
4497b3cb
PP
464 'fields': ('devise_comparaison',
465 ('comp_locale_min', 'comp_locale_max'),
466 ('comp_universite_min', 'comp_universite_max'),
467 ('comp_fonctionpub_min', 'comp_fonctionpub_max'),
468 ('comp_ong_min', 'comp_ong_max'),
469 ('comp_autre_min', 'comp_autre_max'))
6e7c919b
NC
470 }),
471 ('Justification', {
472 'fields': ('justification',)
473 }),
474 ('Autres Metadata', {
4497b3cb 475 'fields': ('date_validation', ('date_debut', 'date_fin'))
6e7c919b
NC
476 }),
477 )
478
babf71ec
NC
479 inlines = (PosteFinancementInline,
480 PostePieceInline,
70561dc2
OL
481 DossierROInline,
482 PosteCommentaireInline, )
6e7c919b 483
70561dc2
OL
484 def save_formset(self, request, form, formset, change):
485 instances = formset.save(commit=False)
486 for instance in instances:
487 if instance.__class__ == rh.PosteCommentaire:
488 instance.owner = request.user
489 instance.save()
490 formset.save_m2m()
6e7c919b 491
aff1a4c6 492
6e7c919b
NC
493class PosteCommentaireAdmin(admin.ModelAdmin):
494 pass
495
6e7c919b 496
babf71ec 497class PosteFinancementAdmin(admin.ModelAdmin):
6e7c919b
NC
498 pass
499
6e7c919b 500
babf71ec 501class PostePieceAdmin(admin.ModelAdmin):
6e7c919b
NC
502 pass
503
6e7c919b 504
babf71ec 505class RemunerationAdmin(admin.ModelAdmin):
6e7c919b
NC
506 pass
507
6e7c919b 508
1eede0db
OL
509class ResponsableImplantationAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
510 fieldsets = AUFMetadataAdminMixin.fieldsets + (
511 (None, {
512 'fields': ('employe', 'implantation', ),
513 }),
514 )
515
6e7c919b 516
43f5653a
OL
517class ServiceAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
518 list_display = ('nom', 'actif', )
519 fieldsets = AUFMetadataAdminMixin.fieldsets + (
520 (None, {
521 'fields': ('nom', ),
522 }),
523 )
6e7c919b 524
43f5653a
OL
525class StatutAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
526 fieldsets = AUFMetadataAdminMixin.fieldsets + (
527 (None, {
528 'fields': ('code', 'nom', ),
529 }),
530 )
6e7c919b 531
babf71ec 532class TauxChangeAdmin(admin.ModelAdmin):
24475cf1
OL
533 list_display = ('taux', 'devise', 'annee', )
534 list_filter = ('devise', )
dcbadfad
OL
535 fieldsets = AUFMetadataAdminMixin.fieldsets + (
536 (None, {
537 'fields': ('taux', 'devise', 'annee', ),
538 }),
539 )
6e7c919b 540
6e7c919b 541class TypeContratAdmin(admin.ModelAdmin):
babf71ec 542 inlines = (ContratInline,)
7376afeb
PP
543 fieldsets = AUFMetadataAdminMixin.fieldsets + (
544 (None, {
545 'fields': ('nom', 'nom_long', ),
546 }),
547 )
6e7c919b 548
6e7c919b 549
240893cb 550class TypePosteAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
d8d7985b 551 search_fields = ('nom', 'nom_feminin', )
52e05b08
OL
552 list_display = ('nom', 'famille_emploi', )
553 list_filter = ('famille_emploi', )
240893cb
OL
554 fieldsets = AUFMetadataAdminMixin.fieldsets + (
555 (None, {
556 'fields': ('nom', 'nom_feminin', 'is_responsable', 'famille_emploi', )
557 }),
558 )
6e7c919b 559
6e7c919b 560
3f486b41 561class TypeRemunerationAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
f7efd29a 562 list_display = ('nom', 'type_paiement', 'nature_remuneration', )
3f486b41
OL
563 #inlines = (RemunerationROInline,) utilité?
564 fieldsets = AUFMetadataAdminMixin.fieldsets + (
565 (None, {
566 'fields': ('nom', 'type_paiement', 'nature_remuneration', )
567 }),
568 )
6e7c919b 569
6e7c919b 570
3f486b41
OL
571class TypeRevalorisationAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
572 #inlines = (RemunerationROInline,) utilité?
573 fieldsets = AUFMetadataAdminMixin.fieldsets + (
574 (None, {
575 'fields': ('nom', )
576 }),
577 )
6e7c919b 578
6e7c919b 579
84fc088b 580class ValeurPointAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
701f3bea 581 list_display = ('_devise_code', '_devise_nom', 'annee', 'valeur', )
84fc088b
OL
582 fieldsets = AUFMetadataAdminMixin.fieldsets + (
583 (None, {
584 'fields': ('valeur', 'devise', 'implantation', 'annee', )
585 }),
586 )
701f3bea
OL
587
588 def _devise_code(self, obj):
589 return obj.devise.code
590 _devise_code.short_description = "Code de la devise"
591
592 def _devise_nom(self, obj):
593 return obj.devise.nom
594 _devise_nom.short_description = "Nom de la devise"
49c98347
PP
595
596
597def calc_remun(dossier):
598 thisyear = datetime.date.today().year
599 thisyearfilter = Q(date_debut__year=thisyear) | Q(date_fin__year=thisyear)
600
601 remunnow = dossier.rh_remuneration_remunerations.filter(thisyearfilter)
602
603 remun_sum = 0
604 remun_sum_euro = 0
605 sums = defaultdict(int)
606 sums_euro = defaultdict(int)
607 for r in remunnow:
608 nature = r.type.nature_remuneration
609 sums[nature] += r.montant
610 sums_euro[nature] += r.montant_euro()
611 remun_sum += r.montant
612 remun_sum_euro += r.montant_euro()
613
614 remun = {}
615 sums = dict(sums)
616 for n, s in sums.iteritems():
617 remun[n] = [sums[n], sums_euro[n]]
618
619 return remun, remun_sum, remun_sum_euro