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