627fb86a2e0242f2409e1eb0ad5f967a5dedc0da
[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 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
212 def _employe(self, dossier):
213 return unicode(dossier.employe)
214 _employe.short_description = u'Employé'
215
216 def save_formset(self, request, form, formset, change):
217 instances = formset.save(commit=False)
218 for instance in instances:
219 if instance.__class__ == rh.DossierCommentaire:
220 instance.owner = request.user
221 instance.save()
222
223 class DossierPieceAdmin(admin.ModelAdmin):
224 pass
225
226
227 class DossierCommentaireAdmin(admin.ModelAdmin):
228 pass
229
230
231 class EmployeAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
232 alphabet_filter = 'nom'
233 search_fields = ('id', 'nom', 'prenom', 'nom_affichage', )
234 inlines = (AyantDroitInline,
235 DossierROInline,
236 EmployePieceInline,
237 EmployeCommentaireInline)
238 fieldsets = AUFMetadataAdminMixin.fieldsets + (
239 ('Identification', {
240 'fields': ('nom', 'prenom', 'nom_affichage', 'nationalite', 'date_naissance', 'genre', )
241 }),
242 ('Informations personnelles', {
243 'fields': ('situation_famille', 'date_entree', )
244 }),
245 ('Coordonnées', {
246 'fields': ('tel_domicile', 'tel_cellulaire', 'adresse', 'ville', 'province', 'code_postal', 'pays', )
247 }),
248 )
249
250 def save_formset(self, request, form, formset, change):
251 instances = formset.save(commit=False)
252 for instance in instances:
253 if instance.__class__ == rh.EmployeCommentaire:
254 instance.owner = request.user
255 instance.save()
256
257 class EmployeCommentaireAdmin(admin.ModelAdmin):
258 pass
259
260
261 class EmployePieceAdmin(admin.ModelAdmin):
262 pass
263
264
265 class EvenementAdmin(admin.ModelAdmin):
266 inlines = (EvenementRemunerationInline,)
267
268
269 class EvenementRemunerationAdmin(admin.ModelAdmin):
270 pass
271
272
273 class FamilleEmploiAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
274 inlines = (TypePosteInline,)
275 fieldsets = AUFMetadataAdminMixin.fieldsets + (
276 (None, {
277 'fields': ('nom', )
278 }),
279 )
280
281
282 class OrganismeBstgAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
283 search_fields = ('nom', )
284 list_display = ('nom', 'type', 'pays', )
285 inlines = (DossierROInline,)
286 fieldsets = AUFMetadataAdminMixin.fieldsets + (
287 (None, {
288 'fields': ('nom', 'type', 'pays', )
289 }),
290 )
291
292
293 class PosteAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
294 alphabet_filter = 'nom'
295 search_fields = ('nom', 'implantation__code', 'implantation__nom', 'implantation__region__code', 'implantation__region__nom', )
296 list_display = ('nom', 'implantation', 'service', 'type_poste', 'date_debut', 'date_fin', )
297 fieldsets = AUFMetadataAdminMixin.fieldsets + (
298 (None, {
299 'fields': ('nom', 'nom_feminin', 'implantation', 'type_poste',
300 'service', 'responsable')
301 }),
302 ('Contrat', {
303 'fields': ('regime_travail', 'regime_travail_nb_heure_semaine')
304 }),
305 ('Recrutement', {
306 'fields': ('local', 'expatrie', 'mise_a_disposition', 'appel')
307 }),
308 ('Rémunération', {
309 'fields': ('classement_min', 'classement_max', 'valeur_point_min',
310 'valeur_point_max', 'devise_min', 'devise_max',
311 'salaire_min', 'salaire_max', 'indemn_min',
312 'indemn_max', 'autre_min', 'autre_max')
313 }),
314 ('Comparatifs de rémunération', {
315 'fields': ('devise_comparaison', 'comp_locale_min',
316 'comp_locale_max', 'comp_universite_min',
317 'comp_universite_max', 'comp_fonctionpub_min',
318 'comp_fonctionpub_max', 'comp_ong_min', 'comp_ong_max',
319 'comp_autre_min', 'comp_autre_max')
320 }),
321 ('Justification', {
322 'fields': ('justification',)
323 }),
324 ('Autres Metadata', {
325 'fields': ('date_validation', 'date_debut', 'date_fin')
326 }),
327 )
328
329 inlines = (PosteFinancementInline,
330 PostePieceInline,
331 DossierROInline,
332 PosteCommentaireInline, )
333
334 def save_formset(self, request, form, formset, change):
335 instances = formset.save(commit=False)
336 for instance in instances:
337 if instance.__class__ == rh.PosteCommentaire:
338 instance.owner = request.user
339 instance.save()
340 formset.save_m2m()
341
342 class PosteCommentaireAdmin(admin.ModelAdmin):
343 pass
344
345
346 class PosteFinancementAdmin(admin.ModelAdmin):
347 pass
348
349
350 class PostePieceAdmin(admin.ModelAdmin):
351 pass
352
353
354 class RemunerationAdmin(admin.ModelAdmin):
355 pass
356
357
358 class ResponsableImplantationAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
359 fieldsets = AUFMetadataAdminMixin.fieldsets + (
360 (None, {
361 'fields': ('employe', 'implantation', ),
362 }),
363 )
364
365
366 class ServiceAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
367 list_display = ('nom', 'actif', )
368 fieldsets = AUFMetadataAdminMixin.fieldsets + (
369 (None, {
370 'fields': ('nom', ),
371 }),
372 )
373
374 class StatutAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
375 fieldsets = AUFMetadataAdminMixin.fieldsets + (
376 (None, {
377 'fields': ('code', 'nom', ),
378 }),
379 )
380
381 class TauxChangeAdmin(admin.ModelAdmin):
382 list_display = ('taux', 'devise', 'annee', )
383 list_filter = ('devise', )
384 fieldsets = AUFMetadataAdminMixin.fieldsets + (
385 (None, {
386 'fields': ('taux', 'devise', 'annee', ),
387 }),
388 )
389
390 class TypeContratAdmin(admin.ModelAdmin):
391 inlines = (ContratInline,)
392
393
394 class TypePosteAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
395 search_fields = ('nom', 'nom_feminin', )
396 list_display = ('nom', 'famille_emploi', )
397 list_filter = ('famille_emploi', )
398 fieldsets = AUFMetadataAdminMixin.fieldsets + (
399 (None, {
400 'fields': ('nom', 'nom_feminin', 'is_responsable', 'famille_emploi', )
401 }),
402 )
403
404
405 class TypeRemunerationAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
406 list_display = ('nom', 'type_paiement', 'nature_remuneration', )
407 #inlines = (RemunerationROInline,) utilité?
408 fieldsets = AUFMetadataAdminMixin.fieldsets + (
409 (None, {
410 'fields': ('nom', 'type_paiement', 'nature_remuneration', )
411 }),
412 )
413
414
415 class TypeRevalorisationAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
416 #inlines = (RemunerationROInline,) utilité?
417 fieldsets = AUFMetadataAdminMixin.fieldsets + (
418 (None, {
419 'fields': ('nom', )
420 }),
421 )
422
423
424 class ValeurPointAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
425 list_display = ('_devise_code', '_devise_nom', 'annee', 'valeur', )
426 fieldsets = AUFMetadataAdminMixin.fieldsets + (
427 (None, {
428 'fields': ('valeur', 'devise', 'implantation', 'annee', )
429 }),
430 )
431
432 def _devise_code(self, obj):
433 return obj.devise.code
434 _devise_code.short_description = "Code de la devise"
435
436 def _devise_nom(self, obj):
437 return obj.devise.nom
438 _devise_nom.short_description = "Nom de la devise"