#1540
[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 model = models.Model # à remplacer dans admin.py
115
116
117 class PosteFinancementInline(admin.TabularInline):
118 model = models.Model # à remplacer dans admin.py
119
120
121 class PostePieceInline(admin.TabularInline):
122 model = models.Model # à remplacer dans admin.py
123
124
125 class RemunerationInline(admin.TabularInline):
126 model = models.Model # à remplacer dans admin.py
127 exclude = METADATA_READONLY_FIELDS + ('actif', )
128 extra = 1
129
130
131 class RemunerationROInline(ReadonlyInlineMixin, RemunerationInline):
132 pass
133
134
135 class TypePosteInline(admin.TabularInline):
136 model = models.Model # à remplacer dans admin.py
137
138
139 # Admins
140
141 class AyantDroitAdmin(admin.ModelAdmin):
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', )
147 inlines = (AyantDroitCommentaireInline,)
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'
174
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
181
182 class AyantDroitCommentaireAdmin(admin.ModelAdmin):
183 pass
184
185
186 class ClassementAdmin(admin.ModelAdmin):
187 pass
188
189
190 class CommentaireAdmin(admin.ModelAdmin):
191 pass
192
193
194 class ContratAdmin(admin.ModelAdmin):
195 pass
196
197
198 class DeviseAdmin(admin.ModelAdmin):
199 pass
200
201
202 class DossierAdmin(MetadataAdminMixin, admin.ModelAdmin,):
203 search_fields = ('employe__nom', 'employe__prenom', )
204 list_display = ('_employe', '_poste', 'date_debut', 'date_fin', )
205 inlines = (DossierPieceInline, ContratInline,
206 RemunerationInline,
207 #EvenementInline,
208 DossierCommentaireInline,
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 )
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é'
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()
245
246 class DossierPieceAdmin(admin.ModelAdmin):
247 pass
248
249
250 class DossierCommentaireAdmin(admin.ModelAdmin):
251 pass
252
253
254 class EmployeAdmin(MetadataAdminMixin, admin.ModelAdmin):
255 inlines = (AyantDroitInline,
256 DossierROInline,
257 EmployePieceInline,
258 EmployeCommentaireInline)
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 )
275
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()
283
284 class EmployeCommentaireAdmin(admin.ModelAdmin):
285 pass
286
287
288 class EmployePieceAdmin(admin.ModelAdmin):
289 pass
290
291
292 class EvenementAdmin(admin.ModelAdmin):
293 inlines = (EvenementRemunerationInline,)
294
295
296 class EvenementRemunerationAdmin(admin.ModelAdmin):
297 pass
298
299
300 class FamilleEmploiAdmin(admin.ModelAdmin):
301 inlines = (TypePosteInline,)
302
303
304 class OrganismeBstgAdmin(admin.ModelAdmin):
305 inlines = (DossierROInline,)
306
307
308 class 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
341 inlines = (PosteFinancementInline,
342 PostePieceInline,
343 PosteCommentaireInline,
344 DossierROInline)
345
346
347 class PosteCommentaireAdmin(admin.ModelAdmin):
348 pass
349
350
351 class PosteFinancementAdmin(admin.ModelAdmin):
352 pass
353
354
355 class PostePieceAdmin(admin.ModelAdmin):
356 pass
357
358
359 class RemunerationAdmin(admin.ModelAdmin):
360 pass
361
362
363 class ResponsableImplantationAdmin(admin.ModelAdmin):
364 pass
365
366
367 class ServiceAdmin(admin.ModelAdmin):
368 inlines = (PosteInline,)
369
370
371 class StatutAdmin(admin.ModelAdmin):
372 inlines = (EmployeInline,)
373
374
375 class TauxChangeAdmin(admin.ModelAdmin):
376 pass
377
378
379 class TypeContratAdmin(admin.ModelAdmin):
380 inlines = (ContratInline,)
381
382
383 class TypePosteAdmin(admin.ModelAdmin):
384 inlines = (PosteInline,)
385
386
387 class TypeRemunerationAdmin(admin.ModelAdmin):
388 inlines = (RemunerationROInline,)
389
390
391 class TypeRevalorisationAdmin(admin.ModelAdmin):
392 inlines = (RemunerationROInline,)
393
394
395 class ValeurPointAdmin(admin.ModelAdmin):
396 pass