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