#1871
[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
51ab4c2c 15class AyantDroitInline(AUFMetadataInlineAdminMixin, admin.StackedInline):
babf71ec 16 model = models.Model # à remplacer dans admin.py
51ab4c2c 17 extra = 0
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'
d9836879 211 _poste.admin_order_field = 'poste__nom'
54d04eed
NC
212
213 def _employe(self, dossier):
214 return unicode(dossier.employe)
215 _employe.short_description = u'Employé'
d9836879
OL
216 _employe.admin_order_field = 'employe__nom'
217
1f2979b8
OL
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()
6e7c919b
NC
224
225class DossierPieceAdmin(admin.ModelAdmin):
226 pass
227
54d04eed 228
6e7c919b
NC
229class DossierCommentaireAdmin(admin.ModelAdmin):
230 pass
231
54d04eed 232
d6985a3a 233class EmployeAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
7ffc5aa4 234 alphabet_filter = 'nom'
d6985a3a 235 search_fields = ('id', 'nom', 'prenom', 'nom_affichage', )
babf71ec
NC
236 inlines = (AyantDroitInline,
237 DossierROInline,
238 EmployePieceInline,
239 EmployeCommentaireInline)
d6985a3a 240 fieldsets = AUFMetadataAdminMixin.fieldsets + (
cf786fb2
OL
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 )
babf71ec 251
cf786fb2
OL
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()
babf71ec
NC
258
259class EmployeCommentaireAdmin(admin.ModelAdmin):
6e7c919b
NC
260 pass
261
54d04eed 262
babf71ec 263class EmployePieceAdmin(admin.ModelAdmin):
6e7c919b
NC
264 pass
265
54d04eed 266
6e7c919b 267class EvenementAdmin(admin.ModelAdmin):
babf71ec 268 inlines = (EvenementRemunerationInline,)
6e7c919b 269
54d04eed 270
6e7c919b
NC
271class EvenementRemunerationAdmin(admin.ModelAdmin):
272 pass
273
54d04eed 274
26dacccc 275class FamilleEmploiAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
babf71ec 276 inlines = (TypePosteInline,)
26dacccc
OL
277 fieldsets = AUFMetadataAdminMixin.fieldsets + (
278 (None, {
279 'fields': ('nom', )
280 }),
281 )
6e7c919b 282
54d04eed 283
43f5653a 284class OrganismeBstgAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
d8d7985b 285 search_fields = ('nom', )
1c8856ef 286 list_display = ('nom', 'type', 'pays', )
babf71ec 287 inlines = (DossierROInline,)
43f5653a
OL
288 fieldsets = AUFMetadataAdminMixin.fieldsets + (
289 (None, {
290 'fields': ('nom', 'type', 'pays', )
291 }),
292 )
6e7c919b 293
54d04eed 294
d2cf315a 295class PosteAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
387ab827 296 alphabet_filter = 'nom'
70561dc2
OL
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', )
d2cf315a 299 fieldsets = AUFMetadataAdminMixin.fieldsets + (
6e7c919b
NC
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
babf71ec
NC
331 inlines = (PosteFinancementInline,
332 PostePieceInline,
70561dc2
OL
333 DossierROInline,
334 PosteCommentaireInline, )
6e7c919b 335
70561dc2
OL
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()
6e7c919b
NC
343
344class PosteCommentaireAdmin(admin.ModelAdmin):
345 pass
346
6e7c919b 347
babf71ec 348class PosteFinancementAdmin(admin.ModelAdmin):
6e7c919b
NC
349 pass
350
6e7c919b 351
babf71ec 352class PostePieceAdmin(admin.ModelAdmin):
6e7c919b
NC
353 pass
354
6e7c919b 355
babf71ec 356class RemunerationAdmin(admin.ModelAdmin):
6e7c919b
NC
357 pass
358
6e7c919b 359
1eede0db
OL
360class ResponsableImplantationAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
361 fieldsets = AUFMetadataAdminMixin.fieldsets + (
362 (None, {
363 'fields': ('employe', 'implantation', ),
364 }),
365 )
366
6e7c919b 367
43f5653a
OL
368class ServiceAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
369 list_display = ('nom', 'actif', )
370 fieldsets = AUFMetadataAdminMixin.fieldsets + (
371 (None, {
372 'fields': ('nom', ),
373 }),
374 )
6e7c919b 375
43f5653a
OL
376class StatutAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
377 fieldsets = AUFMetadataAdminMixin.fieldsets + (
378 (None, {
379 'fields': ('code', 'nom', ),
380 }),
381 )
6e7c919b 382
babf71ec 383class TauxChangeAdmin(admin.ModelAdmin):
24475cf1
OL
384 list_display = ('taux', 'devise', 'annee', )
385 list_filter = ('devise', )
dcbadfad
OL
386 fieldsets = AUFMetadataAdminMixin.fieldsets + (
387 (None, {
388 'fields': ('taux', 'devise', 'annee', ),
389 }),
390 )
6e7c919b 391
6e7c919b 392class TypeContratAdmin(admin.ModelAdmin):
babf71ec 393 inlines = (ContratInline,)
6e7c919b 394
6e7c919b 395
240893cb 396class TypePosteAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
d8d7985b 397 search_fields = ('nom', 'nom_feminin', )
52e05b08
OL
398 list_display = ('nom', 'famille_emploi', )
399 list_filter = ('famille_emploi', )
240893cb
OL
400 fieldsets = AUFMetadataAdminMixin.fieldsets + (
401 (None, {
402 'fields': ('nom', 'nom_feminin', 'is_responsable', 'famille_emploi', )
403 }),
404 )
6e7c919b 405
6e7c919b 406
3f486b41 407class TypeRemunerationAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
f7efd29a 408 list_display = ('nom', 'type_paiement', 'nature_remuneration', )
3f486b41
OL
409 #inlines = (RemunerationROInline,) utilité?
410 fieldsets = AUFMetadataAdminMixin.fieldsets + (
411 (None, {
412 'fields': ('nom', 'type_paiement', 'nature_remuneration', )
413 }),
414 )
6e7c919b 415
6e7c919b 416
3f486b41
OL
417class TypeRevalorisationAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
418 #inlines = (RemunerationROInline,) utilité?
419 fieldsets = AUFMetadataAdminMixin.fieldsets + (
420 (None, {
421 'fields': ('nom', )
422 }),
423 )
6e7c919b 424
6e7c919b 425
84fc088b 426class ValeurPointAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
701f3bea 427 list_display = ('_devise_code', '_devise_nom', 'annee', 'valeur', )
84fc088b
OL
428 fieldsets = AUFMetadataAdminMixin.fieldsets + (
429 (None, {
430 'fields': ('valeur', 'devise', 'implantation', 'annee', )
431 }),
432 )
701f3bea
OL
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"