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