search alphabetic
[auf_rh_dae.git] / project / rh / lib.py
1 # -*- encoding: utf-8 -*-
2
3 from django.db import models
4 from django.contrib import admin
5 from auf.django.metadata.admin import AUFMetadataAdminMixin, AUFMetadataInlineAdminMixin, AUF_METADATA_READONLY_FIELDS
6 from project.rh import models as rh
7
8 # Inlines
9
10 class 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]
13
14
15 class AyantDroitInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
16 model = models.Model # à remplacer dans admin.py
17 extra = 1
18
19
20 class AyantDroitCommentaireInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
21 readonly_fields = ('owner', )
22 model = models.Model # à remplacer dans admin.py
23 extra = 1
24
25
26 class ContratInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
27 model = models.Model # à remplacer dans admin.py
28 extra = 1
29
30
31 class DossierROInline(ReadOnlyInlineMixin, admin.TabularInline):
32 exclude = AUF_METADATA_READONLY_FIELDS
33 model = models.Model # à remplacer dans admin.py
34
35
36 class DossierCommentaireInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
37 readonly_fields = ('owner', )
38 model = models.Model # à remplacer dans admin.py
39 extra = 1
40
41
42 class DossierPieceInline(admin.TabularInline):
43 model = models.Model # à remplacer dans admin.py
44
45
46 class EmployeInline(admin.TabularInline):
47 model = models.Model # à remplacer dans admin.py
48
49 class EmployeCommentaireInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
50 readonly_fields = ('owner', )
51 model = models.Model # à remplacer dans admin.py
52 extra = 1
53
54
55 class EmployePieceInline(admin.TabularInline):
56 model = models.Model # à remplacer dans admin.py
57
58
59 class EvenementInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
60 model = models.Model # à remplacer dans admin.py
61 extra = 1
62
63
64 class EvenementRemunerationInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
65 model = models.Model # à remplacer dans admin.py
66 extra = 1
67
68
69 class PosteCommentaireInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
70 readonly_fields = ('owner', )
71 model = models.Model # à remplacer dans admin.py
72 extra = 1
73
74
75 class PosteFinancementInline(admin.TabularInline):
76 model = models.Model # à remplacer dans admin.py
77
78
79 class PostePieceInline(admin.TabularInline):
80 model = models.Model # à remplacer dans admin.py
81
82
83 class RemunerationInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
84 model = models.Model # à remplacer dans admin.py
85 extra = 1
86
87
88 class RemunerationROInline(ReadOnlyInlineMixin, RemunerationInline):
89 pass
90
91
92 class TypePosteInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
93 model = models.Model # à remplacer dans admin.py
94
95
96 # Admins
97
98 class AyantDroitAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
99 """
100 L'ajout d'un nouvel ayantdroit se fait dans l'admin de l'employé.
101 """
102 alphabet_filter = 'nom'
103 search_fields = ('nom', 'prenom', 'employe__nom', 'employe__prenom', )
104 list_display = ('_employe', 'lien_parente', '_ayantdroit', )
105 inlines = (AyantDroitCommentaireInline,)
106 readonly_fields = AUFMetadataAdminMixin.readonly_fields + ('employe',)
107 fieldsets = AUFMetadataAdminMixin.fieldsets + (
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):
118 super(AyantDroitAdmin, self).save_formset(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()
124 formset.save_m2m()
125
126 def _ayantdroit(self, obj):
127 return unicode(obj)
128 _ayantdroit.short_description = u'Ayant droit'
129
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
136
137 class AyantDroitCommentaireAdmin(admin.ModelAdmin):
138 pass
139
140
141 class ClassementAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
142 fieldsets = AUFMetadataAdminMixin.fieldsets + (
143 (None, {
144 'fields': ('type', 'echelon', 'degre', 'coefficient', )
145 }),
146 )
147
148
149
150 class CommentaireAdmin(admin.ModelAdmin):
151 pass
152
153
154 class ContratAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
155 alphabet_filter = 'dossier__employe__nom'
156 search_fields = ('dossier__employe__nom', 'dossier__employe__prenom', 'dossier__poste__nom', 'dossier__poste__nom_feminin', )
157 list_display = ('id', 'dossier', '_poste', )
158 fieldsets = AUFMetadataAdminMixin.fieldsets + (
159 (None, {
160 'fields': ('dossier', 'type_contrat', 'date_debut', 'date_fin', )
161 }),
162 )
163
164 def lookup_allowed(self, key, value):
165 if key in ('dossier__employe__nom__istartswith', ):
166 return True
167
168 def _poste(self, obj):
169 return obj.dossier.poste
170 _poste.short_description = "Poste"
171
172
173 class DeviseAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
174 fieldsets = AUFMetadataAdminMixin.fieldsets + (
175 (None, {
176 'fields': ('code', 'nom', ),
177 }),
178 )
179
180
181 class DossierAdmin(AUFMetadataAdminMixin, admin.ModelAdmin,):
182 alphabet_filter = 'employe__nom'
183 search_fields = ('employe__nom', 'employe__prenom', 'poste__nom', 'poste__nom_feminin')
184 list_display = ('_employe', '_poste', 'date_debut', 'date_fin', )
185 inlines = (DossierPieceInline, ContratInline,
186 RemunerationInline,
187 #EvenementInline,
188 DossierCommentaireInline,
189 )
190 fieldsets = AUFMetadataAdminMixin.fieldsets + (
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 )
204
205 def lookup_allowed(self, key, value):
206 if key in ('employe__nom__istartswith', ):
207 return True
208
209
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é'
217
218 def save_formset(self, request, form, formset, change):
219 super(DossierAdmin, self).save_formset(request, form, formset, change)
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()
226
227 class DossierPieceAdmin(admin.ModelAdmin):
228 pass
229
230
231 class DossierCommentaireAdmin(admin.ModelAdmin):
232 pass
233
234
235 class EmployeAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
236 alphabet_filter = 'nom'
237 search_fields = ('id', 'nom', 'prenom', 'nom_affichage', )
238 inlines = (AyantDroitInline,
239 DossierROInline,
240 EmployePieceInline,
241 EmployeCommentaireInline)
242 fieldsets = AUFMetadataAdminMixin.fieldsets + (
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 )
253
254 def save_formset(self, request, form, formset, change):
255 super(EmployeAdmin, self).save_formset(request, form, formset, change)
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()
262
263 class EmployeCommentaireAdmin(admin.ModelAdmin):
264 pass
265
266
267 class EmployePieceAdmin(admin.ModelAdmin):
268 pass
269
270
271 class EvenementAdmin(admin.ModelAdmin):
272 inlines = (EvenementRemunerationInline,)
273
274
275 class EvenementRemunerationAdmin(admin.ModelAdmin):
276 pass
277
278
279 class FamilleEmploiAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
280 inlines = (TypePosteInline,)
281 fieldsets = AUFMetadataAdminMixin.fieldsets + (
282 (None, {
283 'fields': ('nom', )
284 }),
285 )
286
287
288 class OrganismeBstgAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
289 search_fields = ('nom', )
290 list_display = ('nom', 'type', 'pays', )
291 inlines = (DossierROInline,)
292 fieldsets = AUFMetadataAdminMixin.fieldsets + (
293 (None, {
294 'fields': ('nom', 'type', 'pays', )
295 }),
296 )
297
298
299 class PosteAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
300 alphabet_filter = 'nom'
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', )
303 fieldsets = AUFMetadataAdminMixin.fieldsets + (
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
335 inlines = (PosteFinancementInline,
336 PostePieceInline,
337 DossierROInline,
338 PosteCommentaireInline, )
339
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()
347
348 class PosteCommentaireAdmin(admin.ModelAdmin):
349 pass
350
351
352 class PosteFinancementAdmin(admin.ModelAdmin):
353 pass
354
355
356 class PostePieceAdmin(admin.ModelAdmin):
357 pass
358
359
360 class RemunerationAdmin(admin.ModelAdmin):
361 pass
362
363
364 class ResponsableImplantationAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
365 fieldsets = AUFMetadataAdminMixin.fieldsets + (
366 (None, {
367 'fields': ('employe', 'implantation', ),
368 }),
369 )
370
371
372 class ServiceAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
373 list_display = ('nom', 'actif', )
374 fieldsets = AUFMetadataAdminMixin.fieldsets + (
375 (None, {
376 'fields': ('nom', ),
377 }),
378 )
379
380 class StatutAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
381 fieldsets = AUFMetadataAdminMixin.fieldsets + (
382 (None, {
383 'fields': ('code', 'nom', ),
384 }),
385 )
386
387 class TauxChangeAdmin(admin.ModelAdmin):
388 list_display = ('taux', 'devise', 'annee', )
389 list_filter = ('devise', )
390 fieldsets = AUFMetadataAdminMixin.fieldsets + (
391 (None, {
392 'fields': ('taux', 'devise', 'annee', ),
393 }),
394 )
395
396 class TypeContratAdmin(admin.ModelAdmin):
397 inlines = (ContratInline,)
398
399
400 class TypePosteAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
401 search_fields = ('nom', 'nom_feminin', )
402 list_display = ('nom', 'famille_emploi', )
403 list_filter = ('famille_emploi', )
404 fieldsets = AUFMetadataAdminMixin.fieldsets + (
405 (None, {
406 'fields': ('nom', 'nom_feminin', 'is_responsable', 'famille_emploi', )
407 }),
408 )
409
410
411 class TypeRemunerationAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
412 list_display = ('nom', 'type_paiement', 'nature_remuneration', )
413 #inlines = (RemunerationROInline,) utilité?
414 fieldsets = AUFMetadataAdminMixin.fieldsets + (
415 (None, {
416 'fields': ('nom', 'type_paiement', 'nature_remuneration', )
417 }),
418 )
419
420
421 class TypeRevalorisationAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
422 #inlines = (RemunerationROInline,) utilité?
423 fieldsets = AUFMetadataAdminMixin.fieldsets + (
424 (None, {
425 'fields': ('nom', )
426 }),
427 )
428
429
430 class ValeurPointAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
431 list_display = ('_devise_code', '_devise_nom', 'annee', 'valeur', )
432 fieldsets = AUFMetadataAdminMixin.fieldsets + (
433 (None, {
434 'fields': ('valeur', 'devise', 'implantation', 'annee', )
435 }),
436 )
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"