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