#1539 type poste
[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
babf71ec 140class ClassementAdmin(admin.ModelAdmin):
6e7c919b
NC
141 pass
142
6e7c919b
NC
143
144class CommentaireAdmin(admin.ModelAdmin):
145 pass
146
147
babf71ec 148class ContratAdmin(admin.ModelAdmin):
c41b7fcc
OL
149 search_fields = ('dossier__employe__nom', 'dossier__employe__prenom', )
150 list_display = ('id', 'dossier', '_poste', )
151
152 def _poste(self, obj):
153 return obj.dossier.poste
154 _poste.short_description = "Poste"
6e7c919b 155
54d04eed 156
babf71ec 157class DeviseAdmin(admin.ModelAdmin):
6e7c919b
NC
158 pass
159
54d04eed 160
d6985a3a 161class DossierAdmin(AUFMetadataAdminMixin, admin.ModelAdmin,):
1f2979b8
OL
162 search_fields = ('employe__nom', 'employe__prenom', )
163 list_display = ('_employe', '_poste', 'date_debut', 'date_fin', )
164 inlines = (DossierPieceInline, ContratInline,
cf786fb2
OL
165 RemunerationInline,
166 #EvenementInline,
167 DossierCommentaireInline,
1f2979b8 168 )
d6985a3a 169 fieldsets = AUFMetadataAdminMixin.fieldsets + (
1f2979b8
OL
170 ('Identification', {
171 'fields': ('employe', 'poste', 'statut', 'organisme_bstg',)
172 }),
173 ('Recrutement', {
174 'fields': ('remplacement', 'statut_residence', )
175 }),
176 ('Rémunération', {
177 'fields': ('classement', 'regime_travail', 'regime_travail_nb_heure_semaine',)
178 }),
179 ('Occupation du Poste par cet Employe', {
180 'fields': ('date_debut', 'date_fin', )
181 }),
182 )
54d04eed
NC
183
184 def _poste(self, dossier):
185 return unicode(dossier.poste.nom)
186 _poste.short_description = u'Poste'
187
188 def _employe(self, dossier):
189 return unicode(dossier.employe)
190 _employe.short_description = u'Employé'
1f2979b8
OL
191
192 def save_formset(self, request, form, formset, change):
d6985a3a 193 super(DossierAdmin, self).save_formset(request, form, formset, change)
1f2979b8
OL
194 instances = formset.save(commit=False)
195 for instance in instances:
196 if instance.__class__ == rh.DossierCommentaire:
197 instance.owner = request.user
198 instance.save()
199 formset.save_m2m()
6e7c919b
NC
200
201class DossierPieceAdmin(admin.ModelAdmin):
202 pass
203
54d04eed 204
6e7c919b
NC
205class DossierCommentaireAdmin(admin.ModelAdmin):
206 pass
207
54d04eed 208
d6985a3a
OL
209class EmployeAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
210 search_fields = ('id', 'nom', 'prenom', 'nom_affichage', )
babf71ec
NC
211 inlines = (AyantDroitInline,
212 DossierROInline,
213 EmployePieceInline,
214 EmployeCommentaireInline)
d6985a3a 215 fieldsets = AUFMetadataAdminMixin.fieldsets + (
cf786fb2
OL
216 ('Identification', {
217 'fields': ('nom', 'prenom', 'nom_affichage', 'nationalite', 'date_naissance', 'genre', )
218 }),
219 ('Informations personnelles', {
220 'fields': ('situation_famille', 'date_entree', )
221 }),
222 ('Coordonnées', {
223 'fields': ('tel_domicile', 'tel_cellulaire', 'adresse', 'ville', 'province', 'code_postal', 'pays', )
224 }),
225 )
babf71ec 226
cf786fb2 227 def save_formset(self, request, form, formset, change):
d6985a3a 228 super(EmployeAdmin, self).save_formset(request, form, formset, change)
cf786fb2
OL
229 instances = formset.save(commit=False)
230 for instance in instances:
231 if instance.__class__ == rh.EmployeCommentaire:
232 instance.owner = request.user
233 instance.save()
234 formset.save_m2m()
babf71ec
NC
235
236class EmployeCommentaireAdmin(admin.ModelAdmin):
6e7c919b
NC
237 pass
238
54d04eed 239
babf71ec 240class EmployePieceAdmin(admin.ModelAdmin):
6e7c919b
NC
241 pass
242
54d04eed 243
6e7c919b 244class EvenementAdmin(admin.ModelAdmin):
babf71ec 245 inlines = (EvenementRemunerationInline,)
6e7c919b 246
54d04eed 247
6e7c919b
NC
248class EvenementRemunerationAdmin(admin.ModelAdmin):
249 pass
250
54d04eed 251
26dacccc 252class FamilleEmploiAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
babf71ec 253 inlines = (TypePosteInline,)
26dacccc
OL
254 fieldsets = AUFMetadataAdminMixin.fieldsets + (
255 (None, {
256 'fields': ('nom', )
257 }),
258 )
6e7c919b 259
54d04eed 260
babf71ec 261class OrganismeBstgAdmin(admin.ModelAdmin):
1c8856ef 262 list_display = ('nom', 'type', 'pays', )
babf71ec 263 inlines = (DossierROInline,)
6e7c919b 264
54d04eed 265
6e7c919b 266class PosteAdmin(admin.ModelAdmin):
70561dc2
OL
267 search_fields = ('nom', 'implantation__code', 'implantation__nom', 'implantation__region__code', 'implantation__region__nom', )
268 list_display = ('nom', 'implantation', 'service', 'type_poste', 'date_debut', 'date_fin', )
6e7c919b
NC
269 fieldsets = (
270 (None, {
271 'fields': ('nom', 'nom_feminin', 'implantation', 'type_poste',
272 'service', 'responsable')
273 }),
274 ('Contrat', {
275 'fields': ('regime_travail', 'regime_travail_nb_heure_semaine')
276 }),
277 ('Recrutement', {
278 'fields': ('local', 'expatrie', 'mise_a_disposition', 'appel')
279 }),
280 ('Rémunération', {
281 'fields': ('classement_min', 'classement_max', 'valeur_point_min',
282 'valeur_point_max', 'devise_min', 'devise_max',
283 'salaire_min', 'salaire_max', 'indemn_min',
284 'indemn_max', 'autre_min', 'autre_max')
285 }),
286 ('Comparatifs de rémunération', {
287 'fields': ('devise_comparaison', 'comp_locale_min',
288 'comp_locale_max', 'comp_universite_min',
289 'comp_universite_max', 'comp_fonctionpub_min',
290 'comp_fonctionpub_max', 'comp_ong_min', 'comp_ong_max',
291 'comp_autre_min', 'comp_autre_max')
292 }),
293 ('Justification', {
294 'fields': ('justification',)
295 }),
296 ('Autres Metadata', {
297 'fields': ('date_validation', 'date_debut', 'date_fin')
298 }),
299 )
300
babf71ec
NC
301 inlines = (PosteFinancementInline,
302 PostePieceInline,
70561dc2
OL
303 DossierROInline,
304 PosteCommentaireInline, )
6e7c919b 305
70561dc2
OL
306 def save_formset(self, request, form, formset, change):
307 instances = formset.save(commit=False)
308 for instance in instances:
309 if instance.__class__ == rh.PosteCommentaire:
310 instance.owner = request.user
311 instance.save()
312 formset.save_m2m()
6e7c919b
NC
313
314class PosteCommentaireAdmin(admin.ModelAdmin):
315 pass
316
6e7c919b 317
babf71ec 318class PosteFinancementAdmin(admin.ModelAdmin):
6e7c919b
NC
319 pass
320
6e7c919b 321
babf71ec 322class PostePieceAdmin(admin.ModelAdmin):
6e7c919b
NC
323 pass
324
6e7c919b 325
babf71ec 326class RemunerationAdmin(admin.ModelAdmin):
6e7c919b
NC
327 pass
328
6e7c919b 329
babf71ec 330class ResponsableImplantationAdmin(admin.ModelAdmin):
6e7c919b
NC
331 pass
332
6e7c919b 333
babf71ec 334class ServiceAdmin(admin.ModelAdmin):
240893cb 335 pass
6e7c919b 336
babf71ec
NC
337class StatutAdmin(admin.ModelAdmin):
338 inlines = (EmployeInline,)
6e7c919b 339
6e7c919b 340
babf71ec 341class TauxChangeAdmin(admin.ModelAdmin):
24475cf1
OL
342 list_display = ('taux', 'devise', 'annee', )
343 list_filter = ('devise', )
6e7c919b 344
6e7c919b 345class TypeContratAdmin(admin.ModelAdmin):
babf71ec 346 inlines = (ContratInline,)
6e7c919b 347
6e7c919b 348
240893cb 349class TypePosteAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
52e05b08
OL
350 list_display = ('nom', 'famille_emploi', )
351 list_filter = ('famille_emploi', )
240893cb
OL
352 fieldsets = AUFMetadataAdminMixin.fieldsets + (
353 (None, {
354 'fields': ('nom', 'nom_feminin', 'is_responsable', 'famille_emploi', )
355 }),
356 )
6e7c919b 357
6e7c919b 358
babf71ec 359class TypeRemunerationAdmin(admin.ModelAdmin):
f7efd29a 360 list_display = ('nom', 'type_paiement', 'nature_remuneration', )
babf71ec 361 inlines = (RemunerationROInline,)
6e7c919b 362
6e7c919b 363
babf71ec
NC
364class TypeRevalorisationAdmin(admin.ModelAdmin):
365 inlines = (RemunerationROInline,)
6e7c919b 366
6e7c919b 367
babf71ec 368class ValeurPointAdmin(admin.ModelAdmin):
701f3bea
OL
369 list_display = ('_devise_code', '_devise_nom', 'annee', 'valeur', )
370
371 def _devise_code(self, obj):
372 return obj.devise.code
373 _devise_code.short_description = "Code de la devise"
374
375 def _devise_nom(self, obj):
376 return obj.devise.nom
377 _devise_nom.short_description = "Nom de la devise"