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