#1539, #1540, #1542
[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):
45 return [f.name for f in self.model._meta.fields]
6e7c919b 46
6e7c919b 47
babf71ec 48# Inlines
6e7c919b 49
babf71ec
NC
50class AyantDroitInline(admin.TabularInline):
51 model = models.Model # à remplacer dans admin.py
6e7c919b 52
54d04eed 53
babf71ec
NC
54class AyantDroitCommentaireInline(admin.TabularInline):
55 model = models.Model # à remplacer dans admin.py
6e7c919b 56
54d04eed 57
babf71ec
NC
58class ContratInline(admin.TabularInline):
59 model = models.Model # à remplacer dans admin.py
1f2979b8
OL
60 exclude = METADATA_READONLY_FIELDS + ('actif', )
61 extra = 1
babf71ec
NC
62
63
64class DossierROInline(ReadonlyInlineMixin, admin.TabularInline):
65 model = models.Model # à remplacer dans admin.py
66
67
1f2979b8
OL
68class DossierCommentaireInline(admin.TabularInline, MetadataAdminMixin):
69 exclude = METADATA_READONLY_FIELDS + ('actif', )
70 readonly_fields = ('owner', )
babf71ec 71 model = models.Model # à remplacer dans admin.py
1f2979b8 72 extra = 1
babf71ec
NC
73
74class DossierPieceInline(admin.TabularInline):
75 model = models.Model # à remplacer dans admin.py
76
77
78class EmployeInline(admin.TabularInline):
79 model = models.Model # à remplacer dans admin.py
80
81
82class EmployeCommentaireInline(admin.TabularInline):
83 model = models.Model # à remplacer dans admin.py
84
85
86class EmployePieceInline(admin.TabularInline):
87 model = models.Model # à remplacer dans admin.py
88
89
1f2979b8 90class EvenementInline(admin.TabularInline, MetadataAdminMixin):
babf71ec 91 model = models.Model # à remplacer dans admin.py
1f2979b8
OL
92 exclude = METADATA_READONLY_FIELDS + ('actif', )
93 extra = 1
babf71ec
NC
94
95
1f2979b8 96class EvenementRemunerationInline(admin.TabularInline, MetadataAdminMixin):
babf71ec 97 model = models.Model # à remplacer dans admin.py
1f2979b8
OL
98 exclude = METADATA_READONLY_FIELDS + ('actif', )
99 extra = 1
babf71ec
NC
100
101
102class PosteInline(admin.TabularInline):
103 model = models.Model # à remplacer dans admin.py
104
105
106class PosteCommentaireInline(admin.TabularInline):
107 model = models.Model # à remplacer dans admin.py
108
109
110class PosteFinancementInline(admin.TabularInline):
111 model = models.Model # à remplacer dans admin.py
112
113
114class PostePieceInline(admin.TabularInline):
115 model = models.Model # à remplacer dans admin.py
116
117
118class RemunerationInline(admin.TabularInline):
119 model = models.Model # à remplacer dans admin.py
1f2979b8
OL
120 exclude = METADATA_READONLY_FIELDS + ('actif', )
121 extra = 1
babf71ec
NC
122
123
124class RemunerationROInline(ReadonlyInlineMixin, RemunerationInline):
6e7c919b
NC
125 pass
126
54d04eed 127
babf71ec
NC
128class TypePosteInline(admin.TabularInline):
129 model = models.Model # à remplacer dans admin.py
130
131
132# Admins
133
134class AyantDroitAdmin(admin.ModelAdmin):
135 inlines = (AyantDroitCommentaireInline,)
136
137
138class AyantDroitCommentaireAdmin(admin.ModelAdmin):
6e7c919b
NC
139 pass
140
54d04eed 141
babf71ec 142class ClassementAdmin(admin.ModelAdmin):
6e7c919b
NC
143 pass
144
6e7c919b
NC
145
146class CommentaireAdmin(admin.ModelAdmin):
147 pass
148
149
babf71ec 150class ContratAdmin(admin.ModelAdmin):
6e7c919b
NC
151 pass
152
54d04eed 153
babf71ec 154class DeviseAdmin(admin.ModelAdmin):
6e7c919b
NC
155 pass
156
54d04eed 157
1f2979b8
OL
158class DossierAdmin(MetadataAdminMixin, admin.ModelAdmin,):
159 search_fields = ('employe__nom', 'employe__prenom', )
160 list_display = ('_employe', '_poste', 'date_debut', 'date_fin', )
161 inlines = (DossierPieceInline, ContratInline,
162 RemunerationInline, EvenementInline, DossierCommentaireInline,
163 )
164 readonly_fields = METADATA_READONLY_FIELDS
165 fieldsets = (
166 ('Metadata', {
167 'classes': ('collapse',),
168 'fields': METADATA_FIELDSET_FIELDS,
169 }),
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):
193 instances = formset.save(commit=False)
194 for instance in instances:
195 if instance.__class__ == rh.DossierCommentaire:
196 instance.owner = request.user
197 instance.save()
198 formset.save_m2m()
6e7c919b
NC
199
200class DossierPieceAdmin(admin.ModelAdmin):
201 pass
202
54d04eed 203
6e7c919b
NC
204class DossierCommentaireAdmin(admin.ModelAdmin):
205 pass
206
54d04eed 207
babf71ec
NC
208class EmployeAdmin(admin.ModelAdmin):
209 inlines = (AyantDroitInline,
210 DossierROInline,
211 EmployePieceInline,
212 EmployeCommentaireInline)
213
214
215class EmployeCommentaireAdmin(admin.ModelAdmin):
6e7c919b
NC
216 pass
217
54d04eed 218
babf71ec 219class EmployePieceAdmin(admin.ModelAdmin):
6e7c919b
NC
220 pass
221
54d04eed 222
6e7c919b 223class EvenementAdmin(admin.ModelAdmin):
babf71ec 224 inlines = (EvenementRemunerationInline,)
6e7c919b 225
54d04eed 226
6e7c919b
NC
227class EvenementRemunerationAdmin(admin.ModelAdmin):
228 pass
229
54d04eed 230
6e7c919b 231class FamilleEmploiAdmin(admin.ModelAdmin):
babf71ec 232 inlines = (TypePosteInline,)
6e7c919b 233
54d04eed 234
babf71ec
NC
235class OrganismeBstgAdmin(admin.ModelAdmin):
236 inlines = (DossierROInline,)
6e7c919b 237
54d04eed 238
6e7c919b
NC
239class PosteAdmin(admin.ModelAdmin):
240 fieldsets = (
241 (None, {
242 'fields': ('nom', 'nom_feminin', 'implantation', 'type_poste',
243 'service', 'responsable')
244 }),
245 ('Contrat', {
246 'fields': ('regime_travail', 'regime_travail_nb_heure_semaine')
247 }),
248 ('Recrutement', {
249 'fields': ('local', 'expatrie', 'mise_a_disposition', 'appel')
250 }),
251 ('Rémunération', {
252 'fields': ('classement_min', 'classement_max', 'valeur_point_min',
253 'valeur_point_max', 'devise_min', 'devise_max',
254 'salaire_min', 'salaire_max', 'indemn_min',
255 'indemn_max', 'autre_min', 'autre_max')
256 }),
257 ('Comparatifs de rémunération', {
258 'fields': ('devise_comparaison', 'comp_locale_min',
259 'comp_locale_max', 'comp_universite_min',
260 'comp_universite_max', 'comp_fonctionpub_min',
261 'comp_fonctionpub_max', 'comp_ong_min', 'comp_ong_max',
262 'comp_autre_min', 'comp_autre_max')
263 }),
264 ('Justification', {
265 'fields': ('justification',)
266 }),
267 ('Autres Metadata', {
268 'fields': ('date_validation', 'date_debut', 'date_fin')
269 }),
270 )
271
babf71ec
NC
272 inlines = (PosteFinancementInline,
273 PostePieceInline,
274 PosteCommentaireInline,
275 DossierROInline)
6e7c919b 276
6e7c919b
NC
277
278class PosteCommentaireAdmin(admin.ModelAdmin):
279 pass
280
6e7c919b 281
babf71ec 282class PosteFinancementAdmin(admin.ModelAdmin):
6e7c919b
NC
283 pass
284
6e7c919b 285
babf71ec 286class PostePieceAdmin(admin.ModelAdmin):
6e7c919b
NC
287 pass
288
6e7c919b 289
babf71ec 290class RemunerationAdmin(admin.ModelAdmin):
6e7c919b
NC
291 pass
292
6e7c919b 293
babf71ec 294class ResponsableImplantationAdmin(admin.ModelAdmin):
6e7c919b
NC
295 pass
296
6e7c919b 297
babf71ec
NC
298class ServiceAdmin(admin.ModelAdmin):
299 inlines = (PosteInline,)
6e7c919b 300
6e7c919b 301
babf71ec
NC
302class StatutAdmin(admin.ModelAdmin):
303 inlines = (EmployeInline,)
6e7c919b 304
6e7c919b 305
babf71ec 306class TauxChangeAdmin(admin.ModelAdmin):
6e7c919b
NC
307 pass
308
6e7c919b 309
6e7c919b 310class TypeContratAdmin(admin.ModelAdmin):
babf71ec 311 inlines = (ContratInline,)
6e7c919b 312
6e7c919b 313
babf71ec
NC
314class TypePosteAdmin(admin.ModelAdmin):
315 inlines = (PosteInline,)
6e7c919b 316
6e7c919b 317
babf71ec
NC
318class TypeRemunerationAdmin(admin.ModelAdmin):
319 inlines = (RemunerationROInline,)
6e7c919b 320
6e7c919b 321
babf71ec
NC
322class TypeRevalorisationAdmin(admin.ModelAdmin):
323 inlines = (RemunerationROInline,)
6e7c919b 324
6e7c919b 325
babf71ec 326class ValeurPointAdmin(admin.ModelAdmin):
6e7c919b 327 pass