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