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