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