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