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