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