list_display contrat #1542
[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
69class PosteInline(admin.TabularInline):
70 model = models.Model # à remplacer dans admin.py
71
72
d6985a3a 73class PosteCommentaireInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
70561dc2 74 readonly_fields = ('owner', )
babf71ec 75 model = models.Model # à remplacer dans admin.py
70561dc2 76 extra = 1
babf71ec
NC
77
78
79class PosteFinancementInline(admin.TabularInline):
80 model = models.Model # à remplacer dans admin.py
81
82
83class PostePieceInline(admin.TabularInline):
84 model = models.Model # à remplacer dans admin.py
85
86
d6985a3a 87class RemunerationInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
babf71ec 88 model = models.Model # à remplacer dans admin.py
1f2979b8 89 extra = 1
babf71ec
NC
90
91
d6985a3a 92class RemunerationROInline(ReadOnlyInlineMixin, RemunerationInline):
6e7c919b
NC
93 pass
94
54d04eed 95
babf71ec
NC
96class TypePosteInline(admin.TabularInline):
97 model = models.Model # à remplacer dans admin.py
98
99
100# Admins
101
d6985a3a 102class AyantDroitAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
cf786fb2
OL
103 """
104 L'ajout d'un nouvel ayantdroit se fait dans l'admin de l'employé.
105 """
106 search_fields = ('nom', 'prenom', 'employe__nom', 'employe__prenom', )
107 list_display = ('_ayantdroit', '_employe', )
babf71ec 108 inlines = (AyantDroitCommentaireInline,)
d6985a3a
OL
109 readonly_fields = AUFMetadataAdminMixin.readonly_fields + ('employe',)
110 fieldsets = AUFMetadataAdminMixin.fieldsets + (
cf786fb2
OL
111 ("Lien avec l'employé", {
112 'fields': ('employe', 'lien_parente', )
113 }),
114
115 ('Identification', {
116 'fields': ('nom', 'prenom', 'nom_affichage', 'nationalite', 'date_naissance', 'genre', )
117 }),
118 )
119
120 def save_formset(self, request, form, formset, change):
d6985a3a 121 super(AyantDroitAdmin, self).save_formset(request, form, formset, change)
cf786fb2
OL
122 instances = formset.save(commit=False)
123 for instance in instances:
124 if instance.__class__ == rh.AyantDroitCommentaire:
125 instance.owner = request.user
126 instance.save()
127 formset.save_m2m()
128
129 def _ayantdroit(self, obj):
130 return unicode(obj)
131 _ayantdroit.short_description = u'Ayant droit'
babf71ec 132
cf786fb2
OL
133 def _employe(self, obj):
134 return unicode(obj.employe)
135 _employe.short_description = u'Employé'
136
137 def has_add_permission(self, request):
138 return False
babf71ec
NC
139
140class AyantDroitCommentaireAdmin(admin.ModelAdmin):
6e7c919b
NC
141 pass
142
54d04eed 143
babf71ec 144class ClassementAdmin(admin.ModelAdmin):
6e7c919b
NC
145 pass
146
6e7c919b
NC
147
148class CommentaireAdmin(admin.ModelAdmin):
149 pass
150
151
babf71ec 152class ContratAdmin(admin.ModelAdmin):
c41b7fcc
OL
153 search_fields = ('dossier__employe__nom', 'dossier__employe__prenom', )
154 list_display = ('id', 'dossier', '_poste', )
155
156 def _poste(self, obj):
157 return obj.dossier.poste
158 _poste.short_description = "Poste"
6e7c919b 159
54d04eed 160
babf71ec 161class DeviseAdmin(admin.ModelAdmin):
6e7c919b
NC
162 pass
163
54d04eed 164
d6985a3a 165class DossierAdmin(AUFMetadataAdminMixin, admin.ModelAdmin,):
1f2979b8
OL
166 search_fields = ('employe__nom', 'employe__prenom', )
167 list_display = ('_employe', '_poste', 'date_debut', 'date_fin', )
168 inlines = (DossierPieceInline, ContratInline,
cf786fb2
OL
169 RemunerationInline,
170 #EvenementInline,
171 DossierCommentaireInline,
1f2979b8 172 )
d6985a3a 173 fieldsets = AUFMetadataAdminMixin.fieldsets + (
1f2979b8
OL
174 ('Identification', {
175 'fields': ('employe', 'poste', 'statut', 'organisme_bstg',)
176 }),
177 ('Recrutement', {
178 'fields': ('remplacement', 'statut_residence', )
179 }),
180 ('Rémunération', {
181 'fields': ('classement', 'regime_travail', 'regime_travail_nb_heure_semaine',)
182 }),
183 ('Occupation du Poste par cet Employe', {
184 'fields': ('date_debut', 'date_fin', )
185 }),
186 )
54d04eed
NC
187
188 def _poste(self, dossier):
189 return unicode(dossier.poste.nom)
190 _poste.short_description = u'Poste'
191
192 def _employe(self, dossier):
193 return unicode(dossier.employe)
194 _employe.short_description = u'Employé'
1f2979b8
OL
195
196 def save_formset(self, request, form, formset, change):
d6985a3a 197 super(DossierAdmin, self).save_formset(request, form, formset, change)
1f2979b8
OL
198 instances = formset.save(commit=False)
199 for instance in instances:
200 if instance.__class__ == rh.DossierCommentaire:
201 instance.owner = request.user
202 instance.save()
203 formset.save_m2m()
6e7c919b
NC
204
205class DossierPieceAdmin(admin.ModelAdmin):
206 pass
207
54d04eed 208
6e7c919b
NC
209class DossierCommentaireAdmin(admin.ModelAdmin):
210 pass
211
54d04eed 212
d6985a3a
OL
213class EmployeAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
214 search_fields = ('id', 'nom', 'prenom', 'nom_affichage', )
babf71ec
NC
215 inlines = (AyantDroitInline,
216 DossierROInline,
217 EmployePieceInline,
218 EmployeCommentaireInline)
d6985a3a 219 fieldsets = AUFMetadataAdminMixin.fieldsets + (
cf786fb2
OL
220 ('Identification', {
221 'fields': ('nom', 'prenom', 'nom_affichage', 'nationalite', 'date_naissance', 'genre', )
222 }),
223 ('Informations personnelles', {
224 'fields': ('situation_famille', 'date_entree', )
225 }),
226 ('Coordonnées', {
227 'fields': ('tel_domicile', 'tel_cellulaire', 'adresse', 'ville', 'province', 'code_postal', 'pays', )
228 }),
229 )
babf71ec 230
cf786fb2 231 def save_formset(self, request, form, formset, change):
d6985a3a 232 super(EmployeAdmin, self).save_formset(request, form, formset, change)
cf786fb2
OL
233 instances = formset.save(commit=False)
234 for instance in instances:
235 if instance.__class__ == rh.EmployeCommentaire:
236 instance.owner = request.user
237 instance.save()
238 formset.save_m2m()
babf71ec
NC
239
240class EmployeCommentaireAdmin(admin.ModelAdmin):
6e7c919b
NC
241 pass
242
54d04eed 243
babf71ec 244class EmployePieceAdmin(admin.ModelAdmin):
6e7c919b
NC
245 pass
246
54d04eed 247
6e7c919b 248class EvenementAdmin(admin.ModelAdmin):
babf71ec 249 inlines = (EvenementRemunerationInline,)
6e7c919b 250
54d04eed 251
6e7c919b
NC
252class EvenementRemunerationAdmin(admin.ModelAdmin):
253 pass
254
54d04eed 255
6e7c919b 256class FamilleEmploiAdmin(admin.ModelAdmin):
babf71ec 257 inlines = (TypePosteInline,)
6e7c919b 258
54d04eed 259
babf71ec
NC
260class OrganismeBstgAdmin(admin.ModelAdmin):
261 inlines = (DossierROInline,)
6e7c919b 262
54d04eed 263
6e7c919b 264class PosteAdmin(admin.ModelAdmin):
70561dc2
OL
265 search_fields = ('nom', 'implantation__code', 'implantation__nom', 'implantation__region__code', 'implantation__region__nom', )
266 list_display = ('nom', 'implantation', 'service', 'type_poste', 'date_debut', 'date_fin', )
6e7c919b
NC
267 fieldsets = (
268 (None, {
269 'fields': ('nom', 'nom_feminin', 'implantation', 'type_poste',
270 'service', 'responsable')
271 }),
272 ('Contrat', {
273 'fields': ('regime_travail', 'regime_travail_nb_heure_semaine')
274 }),
275 ('Recrutement', {
276 'fields': ('local', 'expatrie', 'mise_a_disposition', 'appel')
277 }),
278 ('Rémunération', {
279 'fields': ('classement_min', 'classement_max', 'valeur_point_min',
280 'valeur_point_max', 'devise_min', 'devise_max',
281 'salaire_min', 'salaire_max', 'indemn_min',
282 'indemn_max', 'autre_min', 'autre_max')
283 }),
284 ('Comparatifs de rémunération', {
285 'fields': ('devise_comparaison', 'comp_locale_min',
286 'comp_locale_max', 'comp_universite_min',
287 'comp_universite_max', 'comp_fonctionpub_min',
288 'comp_fonctionpub_max', 'comp_ong_min', 'comp_ong_max',
289 'comp_autre_min', 'comp_autre_max')
290 }),
291 ('Justification', {
292 'fields': ('justification',)
293 }),
294 ('Autres Metadata', {
295 'fields': ('date_validation', 'date_debut', 'date_fin')
296 }),
297 )
298
babf71ec
NC
299 inlines = (PosteFinancementInline,
300 PostePieceInline,
70561dc2
OL
301 DossierROInline,
302 PosteCommentaireInline, )
6e7c919b 303
70561dc2
OL
304 def save_formset(self, request, form, formset, change):
305 instances = formset.save(commit=False)
306 for instance in instances:
307 if instance.__class__ == rh.PosteCommentaire:
308 instance.owner = request.user
309 instance.save()
310 formset.save_m2m()
6e7c919b
NC
311
312class PosteCommentaireAdmin(admin.ModelAdmin):
313 pass
314
6e7c919b 315
babf71ec 316class PosteFinancementAdmin(admin.ModelAdmin):
6e7c919b
NC
317 pass
318
6e7c919b 319
babf71ec 320class PostePieceAdmin(admin.ModelAdmin):
6e7c919b
NC
321 pass
322
6e7c919b 323
babf71ec 324class RemunerationAdmin(admin.ModelAdmin):
6e7c919b
NC
325 pass
326
6e7c919b 327
babf71ec 328class ResponsableImplantationAdmin(admin.ModelAdmin):
6e7c919b
NC
329 pass
330
6e7c919b 331
babf71ec
NC
332class ServiceAdmin(admin.ModelAdmin):
333 inlines = (PosteInline,)
6e7c919b 334
6e7c919b 335
babf71ec
NC
336class StatutAdmin(admin.ModelAdmin):
337 inlines = (EmployeInline,)
6e7c919b 338
6e7c919b 339
babf71ec 340class TauxChangeAdmin(admin.ModelAdmin):
6e7c919b
NC
341 pass
342
6e7c919b 343
6e7c919b 344class TypeContratAdmin(admin.ModelAdmin):
babf71ec 345 inlines = (ContratInline,)
6e7c919b 346
6e7c919b 347
babf71ec
NC
348class TypePosteAdmin(admin.ModelAdmin):
349 inlines = (PosteInline,)
6e7c919b 350
6e7c919b 351
babf71ec
NC
352class TypeRemunerationAdmin(admin.ModelAdmin):
353 inlines = (RemunerationROInline,)
6e7c919b 354
6e7c919b 355
babf71ec
NC
356class TypeRevalorisationAdmin(admin.ModelAdmin):
357 inlines = (RemunerationROInline,)
6e7c919b 358
6e7c919b 359
babf71ec 360class ValeurPointAdmin(admin.ModelAdmin):
6e7c919b 361 pass