#1773
[auf_rh_dae.git] / project / rh / lib.py
CommitLineData
6e7c919b
NC
1# -*- encoding: utf-8 -*-
2
babf71ec 3from django.db import models
6e7c919b 4from django.contrib import admin
d6985a3a 5from auf.django.metadata.admin import AUFMetadataAdminMixin, AUFMetadataInlineAdminMixin, AUF_METADATA_READONLY_FIELDS
babf71ec 6from project.rh import models as rh
6e7c919b 7
d6985a3a 8# Inlines
6e7c919b 9
d6985a3a
OL
10class 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]
6e7c919b
NC
13
14
d6985a3a 15class AyantDroitInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
babf71ec 16 model = models.Model # à remplacer dans admin.py
cf786fb2 17 extra = 1
54d04eed 18
d6985a3a
OL
19
20class AyantDroitCommentaireInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
cf786fb2 21 readonly_fields = ('owner', )
babf71ec 22 model = models.Model # à remplacer dans admin.py
cf786fb2 23 extra = 1
6e7c919b 24
54d04eed 25
d6985a3a 26class ContratInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
babf71ec 27 model = models.Model # à remplacer dans admin.py
1f2979b8 28 extra = 1
babf71ec
NC
29
30
d6985a3a
OL
31class DossierROInline(ReadOnlyInlineMixin, admin.TabularInline):
32 exclude = AUF_METADATA_READONLY_FIELDS
babf71ec 33 model = models.Model # à remplacer dans admin.py
babf71ec 34
d6985a3a
OL
35
36class DossierCommentaireInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
1f2979b8 37 readonly_fields = ('owner', )
babf71ec 38 model = models.Model # à remplacer dans admin.py
1f2979b8 39 extra = 1
babf71ec 40
d6985a3a 41
babf71ec
NC
42class DossierPieceInline(admin.TabularInline):
43 model = models.Model # à remplacer dans admin.py
44
45
46class EmployeInline(admin.TabularInline):
47 model = models.Model # à remplacer dans admin.py
48
d6985a3a 49class EmployeCommentaireInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
cf786fb2 50 readonly_fields = ('owner', )
babf71ec 51 model = models.Model # à remplacer dans admin.py
cf786fb2 52 extra = 1
babf71ec
NC
53
54
55class EmployePieceInline(admin.TabularInline):
56 model = models.Model # à remplacer dans admin.py
57
58
d6985a3a 59class EvenementInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
babf71ec 60 model = models.Model # à remplacer dans admin.py
1f2979b8 61 extra = 1
babf71ec
NC
62
63
d6985a3a 64class EvenementRemunerationInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
babf71ec 65 model = models.Model # à remplacer dans admin.py
1f2979b8 66 extra = 1
babf71ec
NC
67
68
d6985a3a 69class PosteCommentaireInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
70561dc2 70 readonly_fields = ('owner', )
babf71ec 71 model = models.Model # à remplacer dans admin.py
70561dc2 72 extra = 1
babf71ec
NC
73
74
75class PosteFinancementInline(admin.TabularInline):
76 model = models.Model # à remplacer dans admin.py
77
78
79class PostePieceInline(admin.TabularInline):
80 model = models.Model # à remplacer dans admin.py
81
82
d6985a3a 83class RemunerationInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
babf71ec 84 model = models.Model # à remplacer dans admin.py
1f2979b8 85 extra = 1
babf71ec
NC
86
87
d6985a3a 88class RemunerationROInline(ReadOnlyInlineMixin, RemunerationInline):
6e7c919b
NC
89 pass
90
54d04eed 91
26dacccc 92class TypePosteInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
babf71ec
NC
93 model = models.Model # à remplacer dans admin.py
94
95
96# Admins
97
d6985a3a 98class AyantDroitAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
cf786fb2
OL
99 """
100 L'ajout d'un nouvel ayantdroit se fait dans l'admin de l'employé.
101 """
387ab827 102 alphabet_filter = 'nom'
cf786fb2 103 search_fields = ('nom', 'prenom', 'employe__nom', 'employe__prenom', )
1a89b1f3 104 list_display = ('_employe', 'lien_parente', '_ayantdroit', )
babf71ec 105 inlines = (AyantDroitCommentaireInline,)
d6985a3a
OL
106 readonly_fields = AUFMetadataAdminMixin.readonly_fields + ('employe',)
107 fieldsets = AUFMetadataAdminMixin.fieldsets + (
cf786fb2
OL
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()
cf786fb2
OL
123
124 def _ayantdroit(self, obj):
125 return unicode(obj)
126 _ayantdroit.short_description = u'Ayant droit'
babf71ec 127
cf786fb2
OL
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
babf71ec
NC
134
135class AyantDroitCommentaireAdmin(admin.ModelAdmin):
6e7c919b
NC
136 pass
137
54d04eed 138
324bf312
OL
139class ClassementAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
140 fieldsets = AUFMetadataAdminMixin.fieldsets + (
141 (None, {
142 'fields': ('type', 'echelon', 'degre', 'coefficient', )
143 }),
144 )
145
6e7c919b 146
6e7c919b
NC
147
148class CommentaireAdmin(admin.ModelAdmin):
149 pass
150
151
20468a70 152class ContratAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
387ab827 153 alphabet_filter = 'dossier__employe__nom'
d8d7985b 154 search_fields = ('dossier__employe__nom', 'dossier__employe__prenom', 'dossier__poste__nom', 'dossier__poste__nom_feminin', )
c41b7fcc 155 list_display = ('id', 'dossier', '_poste', )
20468a70
OL
156 fieldsets = AUFMetadataAdminMixin.fieldsets + (
157 (None, {
158 'fields': ('dossier', 'type_contrat', 'date_debut', 'date_fin', )
159 }),
160 )
c41b7fcc 161
387ab827
OL
162 def lookup_allowed(self, key, value):
163 if key in ('dossier__employe__nom__istartswith', ):
164 return True
165
c41b7fcc
OL
166 def _poste(self, obj):
167 return obj.dossier.poste
168 _poste.short_description = "Poste"
6e7c919b 169
54d04eed 170
84fc088b
OL
171class DeviseAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
172 fieldsets = AUFMetadataAdminMixin.fieldsets + (
173 (None, {
174 'fields': ('code', 'nom', ),
175 }),
176 )
6e7c919b 177
54d04eed 178
d6985a3a 179class DossierAdmin(AUFMetadataAdminMixin, admin.ModelAdmin,):
387ab827 180 alphabet_filter = 'employe__nom'
d8d7985b 181 search_fields = ('employe__nom', 'employe__prenom', 'poste__nom', 'poste__nom_feminin')
1f2979b8
OL
182 list_display = ('_employe', '_poste', 'date_debut', 'date_fin', )
183 inlines = (DossierPieceInline, ContratInline,
cf786fb2
OL
184 RemunerationInline,
185 #EvenementInline,
186 DossierCommentaireInline,
1f2979b8 187 )
d6985a3a 188 fieldsets = AUFMetadataAdminMixin.fieldsets + (
1f2979b8
OL
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 )
54d04eed 202
387ab827
OL
203 def lookup_allowed(self, key, value):
204 if key in ('employe__nom__istartswith', ):
205 return True
206
207
54d04eed
NC
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é'
1f2979b8
OL
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()
6e7c919b
NC
222
223class DossierPieceAdmin(admin.ModelAdmin):
224 pass
225
54d04eed 226
6e7c919b
NC
227class DossierCommentaireAdmin(admin.ModelAdmin):
228 pass
229
54d04eed 230
d6985a3a 231class EmployeAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
7ffc5aa4 232 alphabet_filter = 'nom'
d6985a3a 233 search_fields = ('id', 'nom', 'prenom', 'nom_affichage', )
babf71ec
NC
234 inlines = (AyantDroitInline,
235 DossierROInline,
236 EmployePieceInline,
237 EmployeCommentaireInline)
d6985a3a 238 fieldsets = AUFMetadataAdminMixin.fieldsets + (
cf786fb2
OL
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 )
babf71ec 249
cf786fb2
OL
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()
babf71ec
NC
256
257class EmployeCommentaireAdmin(admin.ModelAdmin):
6e7c919b
NC
258 pass
259
54d04eed 260
babf71ec 261class EmployePieceAdmin(admin.ModelAdmin):
6e7c919b
NC
262 pass
263
54d04eed 264
6e7c919b 265class EvenementAdmin(admin.ModelAdmin):
babf71ec 266 inlines = (EvenementRemunerationInline,)
6e7c919b 267
54d04eed 268
6e7c919b
NC
269class EvenementRemunerationAdmin(admin.ModelAdmin):
270 pass
271
54d04eed 272
26dacccc 273class FamilleEmploiAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
babf71ec 274 inlines = (TypePosteInline,)
26dacccc
OL
275 fieldsets = AUFMetadataAdminMixin.fieldsets + (
276 (None, {
277 'fields': ('nom', )
278 }),
279 )
6e7c919b 280
54d04eed 281
43f5653a 282class OrganismeBstgAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
d8d7985b 283 search_fields = ('nom', )
1c8856ef 284 list_display = ('nom', 'type', 'pays', )
babf71ec 285 inlines = (DossierROInline,)
43f5653a
OL
286 fieldsets = AUFMetadataAdminMixin.fieldsets + (
287 (None, {
288 'fields': ('nom', 'type', 'pays', )
289 }),
290 )
6e7c919b 291
54d04eed 292
d2cf315a 293class PosteAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
387ab827 294 alphabet_filter = 'nom'
70561dc2
OL
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', )
d2cf315a 297 fieldsets = AUFMetadataAdminMixin.fieldsets + (
6e7c919b
NC
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
babf71ec
NC
329 inlines = (PosteFinancementInline,
330 PostePieceInline,
70561dc2
OL
331 DossierROInline,
332 PosteCommentaireInline, )
6e7c919b 333
70561dc2
OL
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()
6e7c919b
NC
341
342class PosteCommentaireAdmin(admin.ModelAdmin):
343 pass
344
6e7c919b 345
babf71ec 346class PosteFinancementAdmin(admin.ModelAdmin):
6e7c919b
NC
347 pass
348
6e7c919b 349
babf71ec 350class PostePieceAdmin(admin.ModelAdmin):
6e7c919b
NC
351 pass
352
6e7c919b 353
babf71ec 354class RemunerationAdmin(admin.ModelAdmin):
6e7c919b
NC
355 pass
356
6e7c919b 357
1eede0db
OL
358class ResponsableImplantationAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
359 fieldsets = AUFMetadataAdminMixin.fieldsets + (
360 (None, {
361 'fields': ('employe', 'implantation', ),
362 }),
363 )
364
6e7c919b 365
43f5653a
OL
366class ServiceAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
367 list_display = ('nom', 'actif', )
368 fieldsets = AUFMetadataAdminMixin.fieldsets + (
369 (None, {
370 'fields': ('nom', ),
371 }),
372 )
6e7c919b 373
43f5653a
OL
374class StatutAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
375 fieldsets = AUFMetadataAdminMixin.fieldsets + (
376 (None, {
377 'fields': ('code', 'nom', ),
378 }),
379 )
6e7c919b 380
babf71ec 381class TauxChangeAdmin(admin.ModelAdmin):
24475cf1
OL
382 list_display = ('taux', 'devise', 'annee', )
383 list_filter = ('devise', )
dcbadfad
OL
384 fieldsets = AUFMetadataAdminMixin.fieldsets + (
385 (None, {
386 'fields': ('taux', 'devise', 'annee', ),
387 }),
388 )
6e7c919b 389
6e7c919b 390class TypeContratAdmin(admin.ModelAdmin):
babf71ec 391 inlines = (ContratInline,)
6e7c919b 392
6e7c919b 393
240893cb 394class TypePosteAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
d8d7985b 395 search_fields = ('nom', 'nom_feminin', )
52e05b08
OL
396 list_display = ('nom', 'famille_emploi', )
397 list_filter = ('famille_emploi', )
240893cb
OL
398 fieldsets = AUFMetadataAdminMixin.fieldsets + (
399 (None, {
400 'fields': ('nom', 'nom_feminin', 'is_responsable', 'famille_emploi', )
401 }),
402 )
6e7c919b 403
6e7c919b 404
3f486b41 405class TypeRemunerationAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
f7efd29a 406 list_display = ('nom', 'type_paiement', 'nature_remuneration', )
3f486b41
OL
407 #inlines = (RemunerationROInline,) utilité?
408 fieldsets = AUFMetadataAdminMixin.fieldsets + (
409 (None, {
410 'fields': ('nom', 'type_paiement', 'nature_remuneration', )
411 }),
412 )
6e7c919b 413
6e7c919b 414
3f486b41
OL
415class TypeRevalorisationAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
416 #inlines = (RemunerationROInline,) utilité?
417 fieldsets = AUFMetadataAdminMixin.fieldsets + (
418 (None, {
419 'fields': ('nom', )
420 }),
421 )
6e7c919b 422
6e7c919b 423
84fc088b 424class ValeurPointAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
701f3bea 425 list_display = ('_devise_code', '_devise_nom', 'annee', 'valeur', )
84fc088b
OL
426 fieldsets = AUFMetadataAdminMixin.fieldsets + (
427 (None, {
428 'fields': ('valeur', 'devise', 'implantation', 'annee', )
429 }),
430 )
701f3bea
OL
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"