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