61c32e6ce52b8aed5ed6b635ad9d73f137686e02
[auf_rh_dae.git] / project / rh / lib.py
1 # -*- encoding: utf-8 -*-
2
3 import datetime
4 from django.db import models
5 from django.contrib import admin
6
7 from project.rh import models as rh
8
9 # MetaData
10 METADATA_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
20 METADATA_FIELDSET_FIELDS = ('actif', 'date_creation', 'user_creation',
21 'date_modification', 'user_modification',
22 'date_activation', 'user_activation',
23 'date_desactivation', 'user_desactivation',)
24
25 class 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()
42
43 class ReadonlyInlineMixin(object):
44 def get_readonly_fields(self, request, obj=None):
45 return [f.name for f in self.model._meta.fields if f.name not in METADATA_READONLY_FIELDS]
46
47
48 # Inlines
49
50 class AyantDroitInline(admin.TabularInline):
51 exclude = METADATA_READONLY_FIELDS + ('actif', )
52 model = models.Model # à remplacer dans admin.py
53 extra = 1
54
55 class AyantDroitCommentaireInline(admin.TabularInline):
56 exclude = METADATA_READONLY_FIELDS + ('actif', )
57 readonly_fields = ('owner', )
58 model = models.Model # à remplacer dans admin.py
59 extra = 1
60
61
62 class ContratInline(admin.TabularInline):
63 model = models.Model # à remplacer dans admin.py
64 exclude = METADATA_READONLY_FIELDS + ('actif', )
65 extra = 1
66
67
68 class DossierROInline(ReadonlyInlineMixin, admin.TabularInline):
69 model = models.Model # à remplacer dans admin.py
70 exclude = METADATA_READONLY_FIELDS
71
72 class DossierCommentaireInline(admin.TabularInline, MetadataAdminMixin):
73 exclude = METADATA_READONLY_FIELDS + ('actif', )
74 readonly_fields = ('owner', )
75 model = models.Model # à remplacer dans admin.py
76 extra = 1
77
78 class DossierPieceInline(admin.TabularInline):
79 model = models.Model # à remplacer dans admin.py
80
81
82 class EmployeInline(admin.TabularInline):
83 model = models.Model # à remplacer dans admin.py
84
85
86 class EmployeCommentaireInline(admin.TabularInline):
87 exclude = METADATA_READONLY_FIELDS + ('actif', )
88 readonly_fields = ('owner', )
89 model = models.Model # à remplacer dans admin.py
90 extra = 1
91
92
93 class EmployePieceInline(admin.TabularInline):
94 model = models.Model # à remplacer dans admin.py
95
96
97 class EvenementInline(admin.TabularInline, MetadataAdminMixin):
98 model = models.Model # à remplacer dans admin.py
99 exclude = METADATA_READONLY_FIELDS + ('actif', )
100 extra = 1
101
102
103 class EvenementRemunerationInline(admin.TabularInline, MetadataAdminMixin):
104 model = models.Model # à remplacer dans admin.py
105 exclude = METADATA_READONLY_FIELDS + ('actif', )
106 extra = 1
107
108
109 class PosteInline(admin.TabularInline):
110 model = models.Model # à remplacer dans admin.py
111
112
113 class PosteCommentaireInline(admin.TabularInline):
114 exclude = METADATA_READONLY_FIELDS + ('actif', )
115 readonly_fields = ('owner', )
116 model = models.Model # à remplacer dans admin.py
117 extra = 1
118
119
120 class PosteFinancementInline(admin.TabularInline):
121 model = models.Model # à remplacer dans admin.py
122
123
124 class PostePieceInline(admin.TabularInline):
125 model = models.Model # à remplacer dans admin.py
126
127
128 class RemunerationInline(admin.TabularInline):
129 model = models.Model # à remplacer dans admin.py
130 exclude = METADATA_READONLY_FIELDS + ('actif', )
131 extra = 1
132
133
134 class RemunerationROInline(ReadonlyInlineMixin, RemunerationInline):
135 pass
136
137
138 class TypePosteInline(admin.TabularInline):
139 model = models.Model # à remplacer dans admin.py
140
141
142 # Admins
143
144 class AyantDroitAdmin(admin.ModelAdmin):
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', )
150 inlines = (AyantDroitCommentaireInline,)
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'
177
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
184
185 class AyantDroitCommentaireAdmin(admin.ModelAdmin):
186 pass
187
188
189 class ClassementAdmin(admin.ModelAdmin):
190 pass
191
192
193 class CommentaireAdmin(admin.ModelAdmin):
194 pass
195
196
197 class ContratAdmin(admin.ModelAdmin):
198 pass
199
200
201 class DeviseAdmin(admin.ModelAdmin):
202 pass
203
204
205 class DossierAdmin(MetadataAdminMixin, admin.ModelAdmin,):
206 search_fields = ('employe__nom', 'employe__prenom', )
207 list_display = ('_employe', '_poste', 'date_debut', 'date_fin', )
208 inlines = (DossierPieceInline, ContratInline,
209 RemunerationInline,
210 #EvenementInline,
211 DossierCommentaireInline,
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 )
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é'
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()
248
249 class DossierPieceAdmin(admin.ModelAdmin):
250 pass
251
252
253 class DossierCommentaireAdmin(admin.ModelAdmin):
254 pass
255
256
257 class EmployeAdmin(MetadataAdminMixin, admin.ModelAdmin):
258 inlines = (AyantDroitInline,
259 DossierROInline,
260 EmployePieceInline,
261 EmployeCommentaireInline)
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 )
278
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()
286
287 class EmployeCommentaireAdmin(admin.ModelAdmin):
288 pass
289
290
291 class EmployePieceAdmin(admin.ModelAdmin):
292 pass
293
294
295 class EvenementAdmin(admin.ModelAdmin):
296 inlines = (EvenementRemunerationInline,)
297
298
299 class EvenementRemunerationAdmin(admin.ModelAdmin):
300 pass
301
302
303 class FamilleEmploiAdmin(admin.ModelAdmin):
304 inlines = (TypePosteInline,)
305
306
307 class OrganismeBstgAdmin(admin.ModelAdmin):
308 inlines = (DossierROInline,)
309
310
311 class PosteAdmin(admin.ModelAdmin):
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', )
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
346 inlines = (PosteFinancementInline,
347 PostePieceInline,
348 DossierROInline,
349 PosteCommentaireInline, )
350
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()
358
359 class PosteCommentaireAdmin(admin.ModelAdmin):
360 pass
361
362
363 class PosteFinancementAdmin(admin.ModelAdmin):
364 pass
365
366
367 class PostePieceAdmin(admin.ModelAdmin):
368 pass
369
370
371 class RemunerationAdmin(admin.ModelAdmin):
372 pass
373
374
375 class ResponsableImplantationAdmin(admin.ModelAdmin):
376 pass
377
378
379 class ServiceAdmin(admin.ModelAdmin):
380 inlines = (PosteInline,)
381
382
383 class StatutAdmin(admin.ModelAdmin):
384 inlines = (EmployeInline,)
385
386
387 class TauxChangeAdmin(admin.ModelAdmin):
388 pass
389
390
391 class TypeContratAdmin(admin.ModelAdmin):
392 inlines = (ContratInline,)
393
394
395 class TypePosteAdmin(admin.ModelAdmin):
396 inlines = (PosteInline,)
397
398
399 class TypeRemunerationAdmin(admin.ModelAdmin):
400 inlines = (RemunerationROInline,)
401
402
403 class TypeRevalorisationAdmin(admin.ModelAdmin):
404 inlines = (RemunerationROInline,)
405
406
407 class ValeurPointAdmin(admin.ModelAdmin):
408 pass