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