#1539, classement
[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 search_fields = ('nom', 'prenom', 'employe__nom', 'employe__prenom', )
103 list_display = ('_employe', 'lien_parente', '_ayantdroit', )
104 inlines = (AyantDroitCommentaireInline,)
105 readonly_fields = AUFMetadataAdminMixin.readonly_fields + ('employe',)
106 fieldsets = AUFMetadataAdminMixin.fieldsets + (
107 ("Lien avec l'employé", {
108 'fields': ('employe', 'lien_parente', )
109 }),
110
111 ('Identification', {
112 'fields': ('nom', 'prenom', 'nom_affichage', 'nationalite', 'date_naissance', 'genre', )
113 }),
114 )
115
116 def save_formset(self, request, form, formset, change):
117 super(AyantDroitAdmin, self).save_formset(request, form, formset, change)
118 instances = formset.save(commit=False)
119 for instance in instances:
120 if instance.__class__ == rh.AyantDroitCommentaire:
121 instance.owner = request.user
122 instance.save()
123 formset.save_m2m()
124
125 def _ayantdroit(self, obj):
126 return unicode(obj)
127 _ayantdroit.short_description = u'Ayant droit'
128
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
135
136 class AyantDroitCommentaireAdmin(admin.ModelAdmin):
137 pass
138
139
140 class ClassementAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
141 fieldsets = AUFMetadataAdminMixin.fieldsets + (
142 (None, {
143 'fields': ('type', 'echelon', 'degre', 'coefficient', )
144 }),
145 )
146
147
148
149 class CommentaireAdmin(admin.ModelAdmin):
150 pass
151
152
153 class ContratAdmin(admin.ModelAdmin):
154 search_fields = ('dossier__employe__nom', 'dossier__employe__prenom', )
155 list_display = ('id', 'dossier', '_poste', )
156
157 def _poste(self, obj):
158 return obj.dossier.poste
159 _poste.short_description = "Poste"
160
161
162 class DeviseAdmin(admin.ModelAdmin):
163 pass
164
165
166 class DossierAdmin(AUFMetadataAdminMixin, admin.ModelAdmin,):
167 search_fields = ('employe__nom', 'employe__prenom', )
168 list_display = ('_employe', '_poste', 'date_debut', 'date_fin', )
169 inlines = (DossierPieceInline, ContratInline,
170 RemunerationInline,
171 #EvenementInline,
172 DossierCommentaireInline,
173 )
174 fieldsets = AUFMetadataAdminMixin.fieldsets + (
175 ('Identification', {
176 'fields': ('employe', 'poste', 'statut', 'organisme_bstg',)
177 }),
178 ('Recrutement', {
179 'fields': ('remplacement', 'statut_residence', )
180 }),
181 ('Rémunération', {
182 'fields': ('classement', 'regime_travail', 'regime_travail_nb_heure_semaine',)
183 }),
184 ('Occupation du Poste par cet Employe', {
185 'fields': ('date_debut', 'date_fin', )
186 }),
187 )
188
189 def _poste(self, dossier):
190 return unicode(dossier.poste.nom)
191 _poste.short_description = u'Poste'
192
193 def _employe(self, dossier):
194 return unicode(dossier.employe)
195 _employe.short_description = u'Employé'
196
197 def save_formset(self, request, form, formset, change):
198 super(DossierAdmin, self).save_formset(request, form, formset, change)
199 instances = formset.save(commit=False)
200 for instance in instances:
201 if instance.__class__ == rh.DossierCommentaire:
202 instance.owner = request.user
203 instance.save()
204 formset.save_m2m()
205
206 class DossierPieceAdmin(admin.ModelAdmin):
207 pass
208
209
210 class DossierCommentaireAdmin(admin.ModelAdmin):
211 pass
212
213
214 class EmployeAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
215 search_fields = ('id', 'nom', 'prenom', 'nom_affichage', )
216 inlines = (AyantDroitInline,
217 DossierROInline,
218 EmployePieceInline,
219 EmployeCommentaireInline)
220 fieldsets = AUFMetadataAdminMixin.fieldsets + (
221 ('Identification', {
222 'fields': ('nom', 'prenom', 'nom_affichage', 'nationalite', 'date_naissance', 'genre', )
223 }),
224 ('Informations personnelles', {
225 'fields': ('situation_famille', 'date_entree', )
226 }),
227 ('Coordonnées', {
228 'fields': ('tel_domicile', 'tel_cellulaire', 'adresse', 'ville', 'province', 'code_postal', 'pays', )
229 }),
230 )
231
232 def save_formset(self, request, form, formset, change):
233 super(EmployeAdmin, self).save_formset(request, form, formset, change)
234 instances = formset.save(commit=False)
235 for instance in instances:
236 if instance.__class__ == rh.EmployeCommentaire:
237 instance.owner = request.user
238 instance.save()
239 formset.save_m2m()
240
241 class EmployeCommentaireAdmin(admin.ModelAdmin):
242 pass
243
244
245 class EmployePieceAdmin(admin.ModelAdmin):
246 pass
247
248
249 class EvenementAdmin(admin.ModelAdmin):
250 inlines = (EvenementRemunerationInline,)
251
252
253 class EvenementRemunerationAdmin(admin.ModelAdmin):
254 pass
255
256
257 class FamilleEmploiAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
258 inlines = (TypePosteInline,)
259 fieldsets = AUFMetadataAdminMixin.fieldsets + (
260 (None, {
261 'fields': ('nom', )
262 }),
263 )
264
265
266 class OrganismeBstgAdmin(admin.ModelAdmin):
267 list_display = ('nom', 'type', 'pays', )
268 inlines = (DossierROInline,)
269
270
271 class PosteAdmin(admin.ModelAdmin):
272 search_fields = ('nom', 'implantation__code', 'implantation__nom', 'implantation__region__code', 'implantation__region__nom', )
273 list_display = ('nom', 'implantation', 'service', 'type_poste', 'date_debut', 'date_fin', )
274 fieldsets = (
275 (None, {
276 'fields': ('nom', 'nom_feminin', 'implantation', 'type_poste',
277 'service', 'responsable')
278 }),
279 ('Contrat', {
280 'fields': ('regime_travail', 'regime_travail_nb_heure_semaine')
281 }),
282 ('Recrutement', {
283 'fields': ('local', 'expatrie', 'mise_a_disposition', 'appel')
284 }),
285 ('Rémunération', {
286 'fields': ('classement_min', 'classement_max', 'valeur_point_min',
287 'valeur_point_max', 'devise_min', 'devise_max',
288 'salaire_min', 'salaire_max', 'indemn_min',
289 'indemn_max', 'autre_min', 'autre_max')
290 }),
291 ('Comparatifs de rémunération', {
292 'fields': ('devise_comparaison', 'comp_locale_min',
293 'comp_locale_max', 'comp_universite_min',
294 'comp_universite_max', 'comp_fonctionpub_min',
295 'comp_fonctionpub_max', 'comp_ong_min', 'comp_ong_max',
296 'comp_autre_min', 'comp_autre_max')
297 }),
298 ('Justification', {
299 'fields': ('justification',)
300 }),
301 ('Autres Metadata', {
302 'fields': ('date_validation', 'date_debut', 'date_fin')
303 }),
304 )
305
306 inlines = (PosteFinancementInline,
307 PostePieceInline,
308 DossierROInline,
309 PosteCommentaireInline, )
310
311 def save_formset(self, request, form, formset, change):
312 instances = formset.save(commit=False)
313 for instance in instances:
314 if instance.__class__ == rh.PosteCommentaire:
315 instance.owner = request.user
316 instance.save()
317 formset.save_m2m()
318
319 class PosteCommentaireAdmin(admin.ModelAdmin):
320 pass
321
322
323 class PosteFinancementAdmin(admin.ModelAdmin):
324 pass
325
326
327 class PostePieceAdmin(admin.ModelAdmin):
328 pass
329
330
331 class RemunerationAdmin(admin.ModelAdmin):
332 pass
333
334
335 class ResponsableImplantationAdmin(admin.ModelAdmin):
336 pass
337
338
339 class ServiceAdmin(admin.ModelAdmin):
340 pass
341
342 class StatutAdmin(admin.ModelAdmin):
343 inlines = (EmployeInline,)
344
345
346 class TauxChangeAdmin(admin.ModelAdmin):
347 list_display = ('taux', 'devise', 'annee', )
348 list_filter = ('devise', )
349
350 class TypeContratAdmin(admin.ModelAdmin):
351 inlines = (ContratInline,)
352
353
354 class TypePosteAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
355 list_display = ('nom', 'famille_emploi', )
356 list_filter = ('famille_emploi', )
357 fieldsets = AUFMetadataAdminMixin.fieldsets + (
358 (None, {
359 'fields': ('nom', 'nom_feminin', 'is_responsable', 'famille_emploi', )
360 }),
361 )
362
363
364 class TypeRemunerationAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
365 list_display = ('nom', 'type_paiement', 'nature_remuneration', )
366 #inlines = (RemunerationROInline,) utilité?
367 fieldsets = AUFMetadataAdminMixin.fieldsets + (
368 (None, {
369 'fields': ('nom', 'type_paiement', 'nature_remuneration', )
370 }),
371 )
372
373
374 class TypeRevalorisationAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
375 #inlines = (RemunerationROInline,) utilité?
376 fieldsets = AUFMetadataAdminMixin.fieldsets + (
377 (None, {
378 'fields': ('nom', )
379 }),
380 )
381
382
383 class ValeurPointAdmin(admin.ModelAdmin):
384 list_display = ('_devise_code', '_devise_nom', 'annee', 'valeur', )
385
386 def _devise_code(self, obj):
387 return obj.devise.code
388 _devise_code.short_description = "Code de la devise"
389
390 def _devise_nom(self, obj):
391 return obj.devise.nom
392 _devise_nom.short_description = "Nom de la devise"