#1540 #1542 poste
[auf_rh_dae.git] / project / rh / lib.py
CommitLineData
6e7c919b
NC
1# -*- encoding: utf-8 -*-
2
1f2979b8 3import datetime
babf71ec 4from django.db import models
6e7c919b
NC
5from django.contrib import admin
6
babf71ec 7from project.rh import models as rh
6e7c919b 8
1f2979b8
OL
9# MetaData
10METADATA_READONLY_FIELDS = ('supprime',
11 'date_creation',
12 'user_creation',
13 'date_modification',
14 'user_modification',
15 'date_activation',
16 'user_activation',
17 'date_desactivation',
18 'user_desactivation', )
19
20METADATA_FIELDSET_FIELDS = ('actif', 'date_creation', 'user_creation',
21 'date_modification', 'user_modification',
22 'date_activation', 'user_activation',
23 'date_desactivation', 'user_desactivation',)
24
25class MetadataAdminMixin(object):
26 """
27 Surcharge l'admin de base, pour setter automatiquement les metadata
28 """
29 def save_model(self, request, obj, form, change):
30 if change is False:
31 obj.user_creation = request.user
32 obj.date_creation = datetime.datetime.now()
33 obj.user_modification = request.user
34 obj.date_modification = datetime.datetime.now()
35 if form.initial['actif'] is True and obj.actif is False:
36 obj.user_desactivation = request.user
37 obj.date_desactivation = datetime.datetime.now()
38 if form.initial['actif'] is False and obj.actif is True:
39 obj.user_activation = request.user
40 obj.date_activation = datetime.datetime.now()
41 obj.save()
6e7c919b 42
babf71ec
NC
43class ReadonlyInlineMixin(object):
44 def get_readonly_fields(self, request, obj=None):
cf786fb2 45 return [f.name for f in self.model._meta.fields if f.name not in METADATA_READONLY_FIELDS]
6e7c919b 46
6e7c919b 47
babf71ec 48# Inlines
6e7c919b 49
babf71ec 50class AyantDroitInline(admin.TabularInline):
cf786fb2 51 exclude = METADATA_READONLY_FIELDS + ('actif', )
babf71ec 52 model = models.Model # à remplacer dans admin.py
cf786fb2 53 extra = 1
54d04eed 54
babf71ec 55class AyantDroitCommentaireInline(admin.TabularInline):
cf786fb2
OL
56 exclude = METADATA_READONLY_FIELDS + ('actif', )
57 readonly_fields = ('owner', )
babf71ec 58 model = models.Model # à remplacer dans admin.py
cf786fb2 59 extra = 1
6e7c919b 60
54d04eed 61
babf71ec
NC
62class ContratInline(admin.TabularInline):
63 model = models.Model # à remplacer dans admin.py
1f2979b8
OL
64 exclude = METADATA_READONLY_FIELDS + ('actif', )
65 extra = 1
babf71ec
NC
66
67
68class DossierROInline(ReadonlyInlineMixin, admin.TabularInline):
69 model = models.Model # à remplacer dans admin.py
cf786fb2 70 exclude = METADATA_READONLY_FIELDS
babf71ec 71
1f2979b8
OL
72class DossierCommentaireInline(admin.TabularInline, MetadataAdminMixin):
73 exclude = METADATA_READONLY_FIELDS + ('actif', )
74 readonly_fields = ('owner', )
babf71ec 75 model = models.Model # à remplacer dans admin.py
1f2979b8 76 extra = 1
babf71ec
NC
77
78class DossierPieceInline(admin.TabularInline):
79 model = models.Model # à remplacer dans admin.py
80
81
82class EmployeInline(admin.TabularInline):
83 model = models.Model # à remplacer dans admin.py
84
85
86class EmployeCommentaireInline(admin.TabularInline):
cf786fb2
OL
87 exclude = METADATA_READONLY_FIELDS + ('actif', )
88 readonly_fields = ('owner', )
babf71ec 89 model = models.Model # à remplacer dans admin.py
cf786fb2 90 extra = 1
babf71ec
NC
91
92
93class EmployePieceInline(admin.TabularInline):
94 model = models.Model # à remplacer dans admin.py
95
96
1f2979b8 97class EvenementInline(admin.TabularInline, MetadataAdminMixin):
babf71ec 98 model = models.Model # à remplacer dans admin.py
1f2979b8
OL
99 exclude = METADATA_READONLY_FIELDS + ('actif', )
100 extra = 1
babf71ec
NC
101
102
1f2979b8 103class EvenementRemunerationInline(admin.TabularInline, MetadataAdminMixin):
babf71ec 104 model = models.Model # à remplacer dans admin.py
1f2979b8
OL
105 exclude = METADATA_READONLY_FIELDS + ('actif', )
106 extra = 1
babf71ec
NC
107
108
109class PosteInline(admin.TabularInline):
110 model = models.Model # à remplacer dans admin.py
111
112
113class PosteCommentaireInline(admin.TabularInline):
70561dc2
OL
114 exclude = METADATA_READONLY_FIELDS + ('actif', )
115 readonly_fields = ('owner', )
babf71ec 116 model = models.Model # à remplacer dans admin.py
70561dc2 117 extra = 1
babf71ec
NC
118
119
120class PosteFinancementInline(admin.TabularInline):
121 model = models.Model # à remplacer dans admin.py
122
123
124class PostePieceInline(admin.TabularInline):
125 model = models.Model # à remplacer dans admin.py
126
127
128class RemunerationInline(admin.TabularInline):
129 model = models.Model # à remplacer dans admin.py
1f2979b8
OL
130 exclude = METADATA_READONLY_FIELDS + ('actif', )
131 extra = 1
babf71ec
NC
132
133
134class RemunerationROInline(ReadonlyInlineMixin, RemunerationInline):
6e7c919b
NC
135 pass
136
54d04eed 137
babf71ec
NC
138class TypePosteInline(admin.TabularInline):
139 model = models.Model # à remplacer dans admin.py
140
141
142# Admins
143
144class AyantDroitAdmin(admin.ModelAdmin):
cf786fb2
OL
145 """
146 L'ajout d'un nouvel ayantdroit se fait dans l'admin de l'employé.
147 """
148 search_fields = ('nom', 'prenom', 'employe__nom', 'employe__prenom', )
149 list_display = ('_ayantdroit', '_employe', )
babf71ec 150 inlines = (AyantDroitCommentaireInline,)
cf786fb2
OL
151 readonly_fields = METADATA_READONLY_FIELDS + ('employe',)
152 fieldsets = (
153 ('Metadata', {
154 'classes': ('collapse',),
155 'fields': METADATA_FIELDSET_FIELDS,
156 }),
157 ("Lien avec l'employé", {
158 'fields': ('employe', 'lien_parente', )
159 }),
160
161 ('Identification', {
162 'fields': ('nom', 'prenom', 'nom_affichage', 'nationalite', 'date_naissance', 'genre', )
163 }),
164 )
165
166 def save_formset(self, request, form, formset, change):
167 instances = formset.save(commit=False)
168 for instance in instances:
169 if instance.__class__ == rh.AyantDroitCommentaire:
170 instance.owner = request.user
171 instance.save()
172 formset.save_m2m()
173
174 def _ayantdroit(self, obj):
175 return unicode(obj)
176 _ayantdroit.short_description = u'Ayant droit'
babf71ec 177
cf786fb2
OL
178 def _employe(self, obj):
179 return unicode(obj.employe)
180 _employe.short_description = u'Employé'
181
182 def has_add_permission(self, request):
183 return False
babf71ec
NC
184
185class AyantDroitCommentaireAdmin(admin.ModelAdmin):
6e7c919b
NC
186 pass
187
54d04eed 188
babf71ec 189class ClassementAdmin(admin.ModelAdmin):
6e7c919b
NC
190 pass
191
6e7c919b
NC
192
193class CommentaireAdmin(admin.ModelAdmin):
194 pass
195
196
babf71ec 197class ContratAdmin(admin.ModelAdmin):
6e7c919b
NC
198 pass
199
54d04eed 200
babf71ec 201class DeviseAdmin(admin.ModelAdmin):
6e7c919b
NC
202 pass
203
54d04eed 204
1f2979b8
OL
205class DossierAdmin(MetadataAdminMixin, admin.ModelAdmin,):
206 search_fields = ('employe__nom', 'employe__prenom', )
207 list_display = ('_employe', '_poste', 'date_debut', 'date_fin', )
208 inlines = (DossierPieceInline, ContratInline,
cf786fb2
OL
209 RemunerationInline,
210 #EvenementInline,
211 DossierCommentaireInline,
1f2979b8
OL
212 )
213 readonly_fields = METADATA_READONLY_FIELDS
214 fieldsets = (
215 ('Metadata', {
216 'classes': ('collapse',),
217 'fields': METADATA_FIELDSET_FIELDS,
218 }),
219 ('Identification', {
220 'fields': ('employe', 'poste', 'statut', 'organisme_bstg',)
221 }),
222 ('Recrutement', {
223 'fields': ('remplacement', 'statut_residence', )
224 }),
225 ('Rémunération', {
226 'fields': ('classement', 'regime_travail', 'regime_travail_nb_heure_semaine',)
227 }),
228 ('Occupation du Poste par cet Employe', {
229 'fields': ('date_debut', 'date_fin', )
230 }),
231 )
54d04eed
NC
232
233 def _poste(self, dossier):
234 return unicode(dossier.poste.nom)
235 _poste.short_description = u'Poste'
236
237 def _employe(self, dossier):
238 return unicode(dossier.employe)
239 _employe.short_description = u'Employé'
1f2979b8
OL
240
241 def save_formset(self, request, form, formset, change):
242 instances = formset.save(commit=False)
243 for instance in instances:
244 if instance.__class__ == rh.DossierCommentaire:
245 instance.owner = request.user
246 instance.save()
247 formset.save_m2m()
6e7c919b
NC
248
249class DossierPieceAdmin(admin.ModelAdmin):
250 pass
251
54d04eed 252
6e7c919b
NC
253class DossierCommentaireAdmin(admin.ModelAdmin):
254 pass
255
54d04eed 256
cf786fb2 257class EmployeAdmin(MetadataAdminMixin, admin.ModelAdmin):
babf71ec
NC
258 inlines = (AyantDroitInline,
259 DossierROInline,
260 EmployePieceInline,
261 EmployeCommentaireInline)
cf786fb2
OL
262 readonly_fields = METADATA_READONLY_FIELDS
263 fieldsets = (
264 ('Metadata', {
265 'classes': ('collapse',),
266 'fields': METADATA_FIELDSET_FIELDS,
267 }),
268 ('Identification', {
269 'fields': ('nom', 'prenom', 'nom_affichage', 'nationalite', 'date_naissance', 'genre', )
270 }),
271 ('Informations personnelles', {
272 'fields': ('situation_famille', 'date_entree', )
273 }),
274 ('Coordonnées', {
275 'fields': ('tel_domicile', 'tel_cellulaire', 'adresse', 'ville', 'province', 'code_postal', 'pays', )
276 }),
277 )
babf71ec 278
cf786fb2
OL
279 def save_formset(self, request, form, formset, change):
280 instances = formset.save(commit=False)
281 for instance in instances:
282 if instance.__class__ == rh.EmployeCommentaire:
283 instance.owner = request.user
284 instance.save()
285 formset.save_m2m()
babf71ec
NC
286
287class EmployeCommentaireAdmin(admin.ModelAdmin):
6e7c919b
NC
288 pass
289
54d04eed 290
babf71ec 291class EmployePieceAdmin(admin.ModelAdmin):
6e7c919b
NC
292 pass
293
54d04eed 294
6e7c919b 295class EvenementAdmin(admin.ModelAdmin):
babf71ec 296 inlines = (EvenementRemunerationInline,)
6e7c919b 297
54d04eed 298
6e7c919b
NC
299class EvenementRemunerationAdmin(admin.ModelAdmin):
300 pass
301
54d04eed 302
6e7c919b 303class FamilleEmploiAdmin(admin.ModelAdmin):
babf71ec 304 inlines = (TypePosteInline,)
6e7c919b 305
54d04eed 306
babf71ec
NC
307class OrganismeBstgAdmin(admin.ModelAdmin):
308 inlines = (DossierROInline,)
6e7c919b 309
54d04eed 310
6e7c919b 311class PosteAdmin(admin.ModelAdmin):
70561dc2
OL
312 search_fields = ('nom', 'implantation__code', 'implantation__nom', 'implantation__region__code', 'implantation__region__nom', )
313 list_display = ('nom', 'implantation', 'service', 'type_poste', 'date_debut', 'date_fin', )
6e7c919b
NC
314 fieldsets = (
315 (None, {
316 'fields': ('nom', 'nom_feminin', 'implantation', 'type_poste',
317 'service', 'responsable')
318 }),
319 ('Contrat', {
320 'fields': ('regime_travail', 'regime_travail_nb_heure_semaine')
321 }),
322 ('Recrutement', {
323 'fields': ('local', 'expatrie', 'mise_a_disposition', 'appel')
324 }),
325 ('Rémunération', {
326 'fields': ('classement_min', 'classement_max', 'valeur_point_min',
327 'valeur_point_max', 'devise_min', 'devise_max',
328 'salaire_min', 'salaire_max', 'indemn_min',
329 'indemn_max', 'autre_min', 'autre_max')
330 }),
331 ('Comparatifs de rémunération', {
332 'fields': ('devise_comparaison', 'comp_locale_min',
333 'comp_locale_max', 'comp_universite_min',
334 'comp_universite_max', 'comp_fonctionpub_min',
335 'comp_fonctionpub_max', 'comp_ong_min', 'comp_ong_max',
336 'comp_autre_min', 'comp_autre_max')
337 }),
338 ('Justification', {
339 'fields': ('justification',)
340 }),
341 ('Autres Metadata', {
342 'fields': ('date_validation', 'date_debut', 'date_fin')
343 }),
344 )
345
babf71ec
NC
346 inlines = (PosteFinancementInline,
347 PostePieceInline,
70561dc2
OL
348 DossierROInline,
349 PosteCommentaireInline, )
6e7c919b 350
70561dc2
OL
351 def save_formset(self, request, form, formset, change):
352 instances = formset.save(commit=False)
353 for instance in instances:
354 if instance.__class__ == rh.PosteCommentaire:
355 instance.owner = request.user
356 instance.save()
357 formset.save_m2m()
6e7c919b
NC
358
359class PosteCommentaireAdmin(admin.ModelAdmin):
360 pass
361
6e7c919b 362
babf71ec 363class PosteFinancementAdmin(admin.ModelAdmin):
6e7c919b
NC
364 pass
365
6e7c919b 366
babf71ec 367class PostePieceAdmin(admin.ModelAdmin):
6e7c919b
NC
368 pass
369
6e7c919b 370
babf71ec 371class RemunerationAdmin(admin.ModelAdmin):
6e7c919b
NC
372 pass
373
6e7c919b 374
babf71ec 375class ResponsableImplantationAdmin(admin.ModelAdmin):
6e7c919b
NC
376 pass
377
6e7c919b 378
babf71ec
NC
379class ServiceAdmin(admin.ModelAdmin):
380 inlines = (PosteInline,)
6e7c919b 381
6e7c919b 382
babf71ec
NC
383class StatutAdmin(admin.ModelAdmin):
384 inlines = (EmployeInline,)
6e7c919b 385
6e7c919b 386
babf71ec 387class TauxChangeAdmin(admin.ModelAdmin):
6e7c919b
NC
388 pass
389
6e7c919b 390
6e7c919b 391class TypeContratAdmin(admin.ModelAdmin):
babf71ec 392 inlines = (ContratInline,)
6e7c919b 393
6e7c919b 394
babf71ec
NC
395class TypePosteAdmin(admin.ModelAdmin):
396 inlines = (PosteInline,)
6e7c919b 397
6e7c919b 398
babf71ec
NC
399class TypeRemunerationAdmin(admin.ModelAdmin):
400 inlines = (RemunerationROInline,)
6e7c919b 401
6e7c919b 402
babf71ec
NC
403class TypeRevalorisationAdmin(admin.ModelAdmin):
404 inlines = (RemunerationROInline,)
6e7c919b 405
6e7c919b 406
babf71ec 407class ValeurPointAdmin(admin.ModelAdmin):
6e7c919b 408 pass