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