accueil et mon profil RH
[auf_rh_dae.git] / project / rh / lib.py
CommitLineData
6e7c919b
NC
1# -*- encoding: utf-8 -*-
2
babf71ec 3from django.db import models
6e7c919b 4from django.contrib import admin
49449367 5from django.conf import settings
d6985a3a 6from auf.django.metadata.admin import AUFMetadataAdminMixin, AUFMetadataInlineAdminMixin, AUF_METADATA_READONLY_FIELDS
babf71ec 7from project.rh import models as rh
84cbb4c5 8from forms import DossierForm, ContratForm
6e7c919b 9
d6985a3a 10# Inlines
6e7c919b 11
d6985a3a
OL
12class ReadOnlyInlineMixin(object):
13 def get_readonly_fields(self, request, obj=None):
14 return [f.name for f in self.model._meta.fields if f.name not in AUF_METADATA_READONLY_FIELDS]
6e7c919b
NC
15
16
51ab4c2c 17class AyantDroitInline(AUFMetadataInlineAdminMixin, admin.StackedInline):
babf71ec 18 model = models.Model # à remplacer dans admin.py
51ab4c2c 19 extra = 0
54d04eed 20
d6985a3a
OL
21
22class AyantDroitCommentaireInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
cf786fb2 23 readonly_fields = ('owner', )
babf71ec 24 model = models.Model # à remplacer dans admin.py
cf786fb2 25 extra = 1
6e7c919b 26
54d04eed 27
d6985a3a 28class ContratInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
84cbb4c5 29 form = ContratForm
babf71ec 30 model = models.Model # à remplacer dans admin.py
1f2979b8 31 extra = 1
babf71ec
NC
32
33
d6985a3a
OL
34class DossierROInline(ReadOnlyInlineMixin, admin.TabularInline):
35 exclude = AUF_METADATA_READONLY_FIELDS
babf71ec 36 model = models.Model # à remplacer dans admin.py
babf71ec 37
d6985a3a
OL
38
39class DossierCommentaireInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
1f2979b8 40 readonly_fields = ('owner', )
babf71ec 41 model = models.Model # à remplacer dans admin.py
1f2979b8 42 extra = 1
babf71ec 43
d6985a3a 44
babf71ec
NC
45class DossierPieceInline(admin.TabularInline):
46 model = models.Model # à remplacer dans admin.py
47
48
49class EmployeInline(admin.TabularInline):
50 model = models.Model # à remplacer dans admin.py
51
d6985a3a 52class EmployeCommentaireInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
cf786fb2 53 readonly_fields = ('owner', )
babf71ec 54 model = models.Model # à remplacer dans admin.py
cf786fb2 55 extra = 1
babf71ec
NC
56
57
58class EmployePieceInline(admin.TabularInline):
59 model = models.Model # à remplacer dans admin.py
60
61
d6985a3a 62class EvenementInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
babf71ec 63 model = models.Model # à remplacer dans admin.py
1f2979b8 64 extra = 1
babf71ec
NC
65
66
d6985a3a 67class EvenementRemunerationInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
babf71ec 68 model = models.Model # à remplacer dans admin.py
1f2979b8 69 extra = 1
babf71ec
NC
70
71
d6985a3a 72class PosteCommentaireInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
70561dc2 73 readonly_fields = ('owner', )
babf71ec 74 model = models.Model # à remplacer dans admin.py
70561dc2 75 extra = 1
babf71ec
NC
76
77
78class PosteFinancementInline(admin.TabularInline):
79 model = models.Model # à remplacer dans admin.py
80
81
82class PostePieceInline(admin.TabularInline):
83 model = models.Model # à remplacer dans admin.py
84
85
d6985a3a 86class RemunerationInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
babf71ec 87 model = models.Model # à remplacer dans admin.py
1f2979b8 88 extra = 1
babf71ec
NC
89
90
d6985a3a 91class RemunerationROInline(ReadOnlyInlineMixin, RemunerationInline):
6e7c919b
NC
92 pass
93
54d04eed 94
26dacccc 95class TypePosteInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
babf71ec
NC
96 model = models.Model # à remplacer dans admin.py
97
98
99# Admins
100
d6985a3a 101class AyantDroitAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
cf786fb2
OL
102 """
103 L'ajout d'un nouvel ayantdroit se fait dans l'admin de l'employé.
104 """
387ab827 105 alphabet_filter = 'nom'
cf786fb2 106 search_fields = ('nom', 'prenom', 'employe__nom', 'employe__prenom', )
1a89b1f3 107 list_display = ('_employe', 'lien_parente', '_ayantdroit', )
babf71ec 108 inlines = (AyantDroitCommentaireInline,)
d6985a3a
OL
109 readonly_fields = AUFMetadataAdminMixin.readonly_fields + ('employe',)
110 fieldsets = AUFMetadataAdminMixin.fieldsets + (
cf786fb2
OL
111 ("Lien avec l'employé", {
112 'fields': ('employe', 'lien_parente', )
113 }),
114
115 ('Identification', {
116 'fields': ('nom', 'prenom', 'nom_affichage', 'nationalite', 'date_naissance', 'genre', )
117 }),
118 )
119
120 def save_formset(self, request, form, formset, change):
121 instances = formset.save(commit=False)
122 for instance in instances:
123 if instance.__class__ == rh.AyantDroitCommentaire:
124 instance.owner = request.user
125 instance.save()
cf786fb2
OL
126
127 def _ayantdroit(self, obj):
128 return unicode(obj)
129 _ayantdroit.short_description = u'Ayant droit'
babf71ec 130
cf786fb2
OL
131 def _employe(self, obj):
132 return unicode(obj.employe)
133 _employe.short_description = u'Employé'
134
135 def has_add_permission(self, request):
136 return False
babf71ec
NC
137
138class AyantDroitCommentaireAdmin(admin.ModelAdmin):
6e7c919b
NC
139 pass
140
54d04eed 141
324bf312
OL
142class ClassementAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
143 fieldsets = AUFMetadataAdminMixin.fieldsets + (
144 (None, {
145 'fields': ('type', 'echelon', 'degre', 'coefficient', )
146 }),
147 )
148
6e7c919b 149
6e7c919b
NC
150class CommentaireAdmin(admin.ModelAdmin):
151 pass
152
153
84cbb4c5
OL
154#class ContratAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
155# form = ContratForm
156# alphabet_filter = 'dossier__employe__nom'
157# search_fields = ('dossier__employe__nom', 'dossier__employe__prenom', 'dossier__poste__nom', 'dossier__poste__nom_feminin', )
158# list_display = ('id', '_employe', '_poste', 'date_debut', 'date_fin', '_implantation', )
159# fieldsets = AUFMetadataAdminMixin.fieldsets + (
160# (None, {
161# 'fields': ('dossier', 'type_contrat', 'date_debut', 'date_fin', )
162# }),
163# )
164#
165# def lookup_allowed(self, key, value):
166# if key in ('dossier__employe__nom__istartswith', ):
167# return True
168#
169# def _employe(self, obj):
170# return unicode(obj.dossier.employe)
171# _employe.short_description = "Employé"
172#
173# def _poste(self, obj):
174# return obj.dossier.poste.nom
175# _poste.short_description = "Poste"
176#
177# def _implantation(self, obj):
178# return obj.dossier.poste.implantation
179# _poste.short_description = "Implantation"
54d04eed 180
84fc088b
OL
181class DeviseAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
182 fieldsets = AUFMetadataAdminMixin.fieldsets + (
183 (None, {
184 'fields': ('code', 'nom', ),
185 }),
186 )
6e7c919b 187
54d04eed 188
d6985a3a 189class DossierAdmin(AUFMetadataAdminMixin, admin.ModelAdmin,):
84cbb4c5 190 form = DossierForm
387ab827 191 alphabet_filter = 'employe__nom'
d8d7985b 192 search_fields = ('employe__nom', 'employe__prenom', 'poste__nom', 'poste__nom_feminin')
49449367 193 list_display = ('_employe', '_poste', 'date_debut', 'date_fin', '_actif')
1f2979b8 194 inlines = (DossierPieceInline, ContratInline,
cf786fb2
OL
195 RemunerationInline,
196 #EvenementInline,
197 DossierCommentaireInline,
1f2979b8 198 )
d6985a3a 199 fieldsets = AUFMetadataAdminMixin.fieldsets + (
1f2979b8
OL
200 ('Identification', {
201 'fields': ('employe', 'poste', 'statut', 'organisme_bstg',)
202 }),
203 ('Recrutement', {
204 'fields': ('remplacement', 'statut_residence', )
205 }),
206 ('Rémunération', {
207 'fields': ('classement', 'regime_travail', 'regime_travail_nb_heure_semaine',)
208 }),
209 ('Occupation du Poste par cet Employe', {
210 'fields': ('date_debut', 'date_fin', )
211 }),
212 )
54d04eed 213
387ab827 214 def lookup_allowed(self, key, value):
49449367 215 if key in ('employe__nom__istartswith', 'actif__exact', ):
387ab827
OL
216 return True
217
49449367
OL
218 def _actif(self, dossier):
219 if dossier.employe.actif:
220 html = """<img alt="True" src="%simg/admin/icon-yes.gif">"""
221 else:
222 html = """<img alt="False" src="%simg/admin/icon-no.gif">"""
223 return html % settings.ADMIN_MEDIA_PREFIX
224 _actif.allow_tags = u'Employé actif'
225 _actif.short_description = u'Employé actif'
226 _actif.admin_order_field = 'employe__actif'
387ab827 227
54d04eed
NC
228 def _poste(self, dossier):
229 return unicode(dossier.poste.nom)
230 _poste.short_description = u'Poste'
d9836879 231 _poste.admin_order_field = 'poste__nom'
54d04eed
NC
232
233 def _employe(self, dossier):
234 return unicode(dossier.employe)
235 _employe.short_description = u'Employé'
d9836879
OL
236 _employe.admin_order_field = 'employe__nom'
237
1f2979b8
OL
238 def save_formset(self, request, form, formset, change):
239 instances = formset.save(commit=False)
240 for instance in instances:
241 if instance.__class__ == rh.DossierCommentaire:
242 instance.owner = request.user
243 instance.save()
6e7c919b
NC
244
245class DossierPieceAdmin(admin.ModelAdmin):
246 pass
247
54d04eed 248
6e7c919b
NC
249class DossierCommentaireAdmin(admin.ModelAdmin):
250 pass
251
54d04eed 252
d6985a3a 253class EmployeAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
7ffc5aa4 254 alphabet_filter = 'nom'
49449367
OL
255 search_fields = ('id', 'nom', 'prenom', 'nom_affichage', 'actif', )
256 list_filter = ('actif', )
257 ordering = ('nom', )
258 actions = ('desactiver', )
259 list_display = ('nom', 'prenom', 'actif', )
babf71ec
NC
260 inlines = (AyantDroitInline,
261 DossierROInline,
262 EmployePieceInline,
263 EmployeCommentaireInline)
d6985a3a 264 fieldsets = AUFMetadataAdminMixin.fieldsets + (
cf786fb2
OL
265 ('Identification', {
266 'fields': ('nom', 'prenom', 'nom_affichage', 'nationalite', 'date_naissance', 'genre', )
267 }),
268 ('Informations personnelles', {
269 'fields': ('situation_famille', 'date_entree', )
270 }),
271 ('Coordonnées', {
272 'fields': ('tel_domicile', 'tel_cellulaire', 'adresse', 'ville', 'province', 'code_postal', 'pays', )
273 }),
274 )
babf71ec 275
cf786fb2
OL
276 def save_formset(self, request, form, formset, change):
277 instances = formset.save(commit=False)
278 for instance in instances:
279 if instance.__class__ == rh.EmployeCommentaire:
280 instance.owner = request.user
281 instance.save()
babf71ec
NC
282
283class EmployeCommentaireAdmin(admin.ModelAdmin):
6e7c919b
NC
284 pass
285
54d04eed 286
babf71ec 287class EmployePieceAdmin(admin.ModelAdmin):
6e7c919b
NC
288 pass
289
54d04eed 290
6e7c919b 291class EvenementAdmin(admin.ModelAdmin):
babf71ec 292 inlines = (EvenementRemunerationInline,)
6e7c919b 293
54d04eed 294
6e7c919b
NC
295class EvenementRemunerationAdmin(admin.ModelAdmin):
296 pass
297
54d04eed 298
26dacccc 299class FamilleEmploiAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
babf71ec 300 inlines = (TypePosteInline,)
26dacccc
OL
301 fieldsets = AUFMetadataAdminMixin.fieldsets + (
302 (None, {
303 'fields': ('nom', )
304 }),
305 )
6e7c919b 306
54d04eed 307
43f5653a 308class OrganismeBstgAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
d8d7985b 309 search_fields = ('nom', )
1c8856ef 310 list_display = ('nom', 'type', 'pays', )
babf71ec 311 inlines = (DossierROInline,)
43f5653a
OL
312 fieldsets = AUFMetadataAdminMixin.fieldsets + (
313 (None, {
314 'fields': ('nom', 'type', 'pays', )
315 }),
316 )
6e7c919b 317
54d04eed 318
d2cf315a 319class PosteAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
387ab827 320 alphabet_filter = 'nom'
70561dc2
OL
321 search_fields = ('nom', 'implantation__code', 'implantation__nom', 'implantation__region__code', 'implantation__region__nom', )
322 list_display = ('nom', 'implantation', 'service', 'type_poste', 'date_debut', 'date_fin', )
d2cf315a 323 fieldsets = AUFMetadataAdminMixin.fieldsets + (
6e7c919b
NC
324 (None, {
325 'fields': ('nom', 'nom_feminin', 'implantation', 'type_poste',
326 'service', 'responsable')
327 }),
328 ('Contrat', {
329 'fields': ('regime_travail', 'regime_travail_nb_heure_semaine')
330 }),
331 ('Recrutement', {
332 'fields': ('local', 'expatrie', 'mise_a_disposition', 'appel')
333 }),
334 ('Rémunération', {
335 'fields': ('classement_min', 'classement_max', 'valeur_point_min',
336 'valeur_point_max', 'devise_min', 'devise_max',
337 'salaire_min', 'salaire_max', 'indemn_min',
338 'indemn_max', 'autre_min', 'autre_max')
339 }),
340 ('Comparatifs de rémunération', {
341 'fields': ('devise_comparaison', 'comp_locale_min',
342 'comp_locale_max', 'comp_universite_min',
343 'comp_universite_max', 'comp_fonctionpub_min',
344 'comp_fonctionpub_max', 'comp_ong_min', 'comp_ong_max',
345 'comp_autre_min', 'comp_autre_max')
346 }),
347 ('Justification', {
348 'fields': ('justification',)
349 }),
350 ('Autres Metadata', {
351 'fields': ('date_validation', 'date_debut', 'date_fin')
352 }),
353 )
354
babf71ec
NC
355 inlines = (PosteFinancementInline,
356 PostePieceInline,
70561dc2
OL
357 DossierROInline,
358 PosteCommentaireInline, )
6e7c919b 359
70561dc2
OL
360 def save_formset(self, request, form, formset, change):
361 instances = formset.save(commit=False)
362 for instance in instances:
363 if instance.__class__ == rh.PosteCommentaire:
364 instance.owner = request.user
365 instance.save()
366 formset.save_m2m()
6e7c919b
NC
367
368class PosteCommentaireAdmin(admin.ModelAdmin):
369 pass
370
6e7c919b 371
babf71ec 372class PosteFinancementAdmin(admin.ModelAdmin):
6e7c919b
NC
373 pass
374
6e7c919b 375
babf71ec 376class PostePieceAdmin(admin.ModelAdmin):
6e7c919b
NC
377 pass
378
6e7c919b 379
babf71ec 380class RemunerationAdmin(admin.ModelAdmin):
6e7c919b
NC
381 pass
382
6e7c919b 383
1eede0db
OL
384class ResponsableImplantationAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
385 fieldsets = AUFMetadataAdminMixin.fieldsets + (
386 (None, {
387 'fields': ('employe', 'implantation', ),
388 }),
389 )
390
6e7c919b 391
43f5653a
OL
392class ServiceAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
393 list_display = ('nom', 'actif', )
394 fieldsets = AUFMetadataAdminMixin.fieldsets + (
395 (None, {
396 'fields': ('nom', ),
397 }),
398 )
6e7c919b 399
43f5653a
OL
400class StatutAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
401 fieldsets = AUFMetadataAdminMixin.fieldsets + (
402 (None, {
403 'fields': ('code', 'nom', ),
404 }),
405 )
6e7c919b 406
babf71ec 407class TauxChangeAdmin(admin.ModelAdmin):
24475cf1
OL
408 list_display = ('taux', 'devise', 'annee', )
409 list_filter = ('devise', )
dcbadfad
OL
410 fieldsets = AUFMetadataAdminMixin.fieldsets + (
411 (None, {
412 'fields': ('taux', 'devise', 'annee', ),
413 }),
414 )
6e7c919b 415
6e7c919b 416class TypeContratAdmin(admin.ModelAdmin):
babf71ec 417 inlines = (ContratInline,)
6e7c919b 418
6e7c919b 419
240893cb 420class TypePosteAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
d8d7985b 421 search_fields = ('nom', 'nom_feminin', )
52e05b08
OL
422 list_display = ('nom', 'famille_emploi', )
423 list_filter = ('famille_emploi', )
240893cb
OL
424 fieldsets = AUFMetadataAdminMixin.fieldsets + (
425 (None, {
426 'fields': ('nom', 'nom_feminin', 'is_responsable', 'famille_emploi', )
427 }),
428 )
6e7c919b 429
6e7c919b 430
3f486b41 431class TypeRemunerationAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
f7efd29a 432 list_display = ('nom', 'type_paiement', 'nature_remuneration', )
3f486b41
OL
433 #inlines = (RemunerationROInline,) utilité?
434 fieldsets = AUFMetadataAdminMixin.fieldsets + (
435 (None, {
436 'fields': ('nom', 'type_paiement', 'nature_remuneration', )
437 }),
438 )
6e7c919b 439
6e7c919b 440
3f486b41
OL
441class TypeRevalorisationAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
442 #inlines = (RemunerationROInline,) utilité?
443 fieldsets = AUFMetadataAdminMixin.fieldsets + (
444 (None, {
445 'fields': ('nom', )
446 }),
447 )
6e7c919b 448
6e7c919b 449
84fc088b 450class ValeurPointAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
701f3bea 451 list_display = ('_devise_code', '_devise_nom', 'annee', 'valeur', )
84fc088b
OL
452 fieldsets = AUFMetadataAdminMixin.fieldsets + (
453 (None, {
454 'fields': ('valeur', 'devise', 'implantation', 'annee', )
455 }),
456 )
701f3bea
OL
457
458 def _devise_code(self, obj):
459 return obj.devise.code
460 _devise_code.short_description = "Code de la devise"
461
462 def _devise_nom(self, obj):
463 return obj.devise.nom
464 _devise_nom.short_description = "Nom de la devise"