valeur point #1542
[auf_rh_dae.git] / project / rh / lib.py
CommitLineData
6e7c919b
NC
1# -*- encoding: utf-8 -*-
2
babf71ec 3from django.db import models
6e7c919b 4from django.contrib import admin
d6985a3a 5from auf.django.metadata.admin import AUFMetadataAdminMixin, AUFMetadataInlineAdminMixin, AUF_METADATA_READONLY_FIELDS
babf71ec 6from project.rh import models as rh
6e7c919b 7
d6985a3a 8# Inlines
6e7c919b 9
d6985a3a
OL
10class 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]
6e7c919b
NC
13
14
d6985a3a 15class AyantDroitInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
babf71ec 16 model = models.Model # à remplacer dans admin.py
cf786fb2 17 extra = 1
54d04eed 18
d6985a3a
OL
19
20class AyantDroitCommentaireInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
cf786fb2 21 readonly_fields = ('owner', )
babf71ec 22 model = models.Model # à remplacer dans admin.py
cf786fb2 23 extra = 1
6e7c919b 24
54d04eed 25
d6985a3a 26class ContratInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
babf71ec 27 model = models.Model # à remplacer dans admin.py
1f2979b8 28 extra = 1
babf71ec
NC
29
30
d6985a3a
OL
31class DossierROInline(ReadOnlyInlineMixin, admin.TabularInline):
32 exclude = AUF_METADATA_READONLY_FIELDS
babf71ec 33 model = models.Model # à remplacer dans admin.py
babf71ec 34
d6985a3a
OL
35
36class DossierCommentaireInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
1f2979b8 37 readonly_fields = ('owner', )
babf71ec 38 model = models.Model # à remplacer dans admin.py
1f2979b8 39 extra = 1
babf71ec 40
d6985a3a 41
babf71ec
NC
42class DossierPieceInline(admin.TabularInline):
43 model = models.Model # à remplacer dans admin.py
44
45
46class EmployeInline(admin.TabularInline):
47 model = models.Model # à remplacer dans admin.py
48
d6985a3a 49class EmployeCommentaireInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
cf786fb2 50 readonly_fields = ('owner', )
babf71ec 51 model = models.Model # à remplacer dans admin.py
cf786fb2 52 extra = 1
babf71ec
NC
53
54
55class EmployePieceInline(admin.TabularInline):
56 model = models.Model # à remplacer dans admin.py
57
58
d6985a3a 59class EvenementInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
babf71ec 60 model = models.Model # à remplacer dans admin.py
1f2979b8 61 extra = 1
babf71ec
NC
62
63
d6985a3a 64class EvenementRemunerationInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
babf71ec 65 model = models.Model # à remplacer dans admin.py
1f2979b8 66 extra = 1
babf71ec
NC
67
68
69class PosteInline(admin.TabularInline):
70 model = models.Model # à remplacer dans admin.py
71
72
d6985a3a 73class PosteCommentaireInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
70561dc2 74 readonly_fields = ('owner', )
babf71ec 75 model = models.Model # à remplacer dans admin.py
70561dc2 76 extra = 1
babf71ec
NC
77
78
79class PosteFinancementInline(admin.TabularInline):
80 model = models.Model # à remplacer dans admin.py
81
82
83class PostePieceInline(admin.TabularInline):
84 model = models.Model # à remplacer dans admin.py
85
86
d6985a3a 87class RemunerationInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
babf71ec 88 model = models.Model # à remplacer dans admin.py
1f2979b8 89 extra = 1
babf71ec
NC
90
91
d6985a3a 92class RemunerationROInline(ReadOnlyInlineMixin, RemunerationInline):
6e7c919b
NC
93 pass
94
54d04eed 95
babf71ec
NC
96class TypePosteInline(admin.TabularInline):
97 model = models.Model # à remplacer dans admin.py
98
99
100# Admins
101
d6985a3a 102class AyantDroitAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
cf786fb2
OL
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', )
1a89b1f3 107 list_display = ('_employe', 'lien_parente', '_ayantdroit', )
babf71ec 108 inlines = (AyantDroitCommentaireInline,)
d6985a3a
OL
109 readonly_fields = AUFMetadataAdminMixin.readonly_fields + ('employe',)
110 fieldsets = AUFMetadataAdminMixin.fieldsets + (
cf786fb2
OL
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):
d6985a3a 121 super(AyantDroitAdmin, self).save_formset(request, form, formset, change)
cf786fb2
OL
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'
babf71ec 132
cf786fb2
OL
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
babf71ec
NC
139
140class AyantDroitCommentaireAdmin(admin.ModelAdmin):
6e7c919b
NC
141 pass
142
54d04eed 143
babf71ec 144class ClassementAdmin(admin.ModelAdmin):
6e7c919b
NC
145 pass
146
6e7c919b
NC
147
148class CommentaireAdmin(admin.ModelAdmin):
149 pass
150
151
babf71ec 152class ContratAdmin(admin.ModelAdmin):
c41b7fcc
OL
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"
6e7c919b 159
54d04eed 160
babf71ec 161class DeviseAdmin(admin.ModelAdmin):
6e7c919b
NC
162 pass
163
54d04eed 164
d6985a3a 165class DossierAdmin(AUFMetadataAdminMixin, admin.ModelAdmin,):
1f2979b8
OL
166 search_fields = ('employe__nom', 'employe__prenom', )
167 list_display = ('_employe', '_poste', 'date_debut', 'date_fin', )
168 inlines = (DossierPieceInline, ContratInline,
cf786fb2
OL
169 RemunerationInline,
170 #EvenementInline,
171 DossierCommentaireInline,
1f2979b8 172 )
d6985a3a 173 fieldsets = AUFMetadataAdminMixin.fieldsets + (
1f2979b8
OL
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 )
54d04eed
NC
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é'
1f2979b8
OL
195
196 def save_formset(self, request, form, formset, change):
d6985a3a 197 super(DossierAdmin, self).save_formset(request, form, formset, change)
1f2979b8
OL
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()
6e7c919b
NC
204
205class DossierPieceAdmin(admin.ModelAdmin):
206 pass
207
54d04eed 208
6e7c919b
NC
209class DossierCommentaireAdmin(admin.ModelAdmin):
210 pass
211
54d04eed 212
d6985a3a
OL
213class EmployeAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
214 search_fields = ('id', 'nom', 'prenom', 'nom_affichage', )
babf71ec
NC
215 inlines = (AyantDroitInline,
216 DossierROInline,
217 EmployePieceInline,
218 EmployeCommentaireInline)
d6985a3a 219 fieldsets = AUFMetadataAdminMixin.fieldsets + (
cf786fb2
OL
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 )
babf71ec 230
cf786fb2 231 def save_formset(self, request, form, formset, change):
d6985a3a 232 super(EmployeAdmin, self).save_formset(request, form, formset, change)
cf786fb2
OL
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()
babf71ec
NC
239
240class EmployeCommentaireAdmin(admin.ModelAdmin):
6e7c919b
NC
241 pass
242
54d04eed 243
babf71ec 244class EmployePieceAdmin(admin.ModelAdmin):
6e7c919b
NC
245 pass
246
54d04eed 247
6e7c919b 248class EvenementAdmin(admin.ModelAdmin):
babf71ec 249 inlines = (EvenementRemunerationInline,)
6e7c919b 250
54d04eed 251
6e7c919b
NC
252class EvenementRemunerationAdmin(admin.ModelAdmin):
253 pass
254
54d04eed 255
6e7c919b 256class FamilleEmploiAdmin(admin.ModelAdmin):
babf71ec 257 inlines = (TypePosteInline,)
6e7c919b 258
54d04eed 259
babf71ec 260class OrganismeBstgAdmin(admin.ModelAdmin):
1c8856ef 261 list_display = ('nom', 'type', 'pays', )
babf71ec 262 inlines = (DossierROInline,)
6e7c919b 263
54d04eed 264
6e7c919b 265class PosteAdmin(admin.ModelAdmin):
70561dc2
OL
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', )
6e7c919b
NC
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
babf71ec
NC
300 inlines = (PosteFinancementInline,
301 PostePieceInline,
70561dc2
OL
302 DossierROInline,
303 PosteCommentaireInline, )
6e7c919b 304
70561dc2
OL
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()
6e7c919b
NC
312
313class PosteCommentaireAdmin(admin.ModelAdmin):
314 pass
315
6e7c919b 316
babf71ec 317class PosteFinancementAdmin(admin.ModelAdmin):
6e7c919b
NC
318 pass
319
6e7c919b 320
babf71ec 321class PostePieceAdmin(admin.ModelAdmin):
6e7c919b
NC
322 pass
323
6e7c919b 324
babf71ec 325class RemunerationAdmin(admin.ModelAdmin):
6e7c919b
NC
326 pass
327
6e7c919b 328
babf71ec 329class ResponsableImplantationAdmin(admin.ModelAdmin):
6e7c919b
NC
330 pass
331
6e7c919b 332
babf71ec
NC
333class ServiceAdmin(admin.ModelAdmin):
334 inlines = (PosteInline,)
6e7c919b 335
6e7c919b 336
babf71ec
NC
337class StatutAdmin(admin.ModelAdmin):
338 inlines = (EmployeInline,)
6e7c919b 339
6e7c919b 340
babf71ec 341class TauxChangeAdmin(admin.ModelAdmin):
24475cf1
OL
342 list_display = ('taux', 'devise', 'annee', )
343 list_filter = ('devise', )
6e7c919b 344
6e7c919b 345class TypeContratAdmin(admin.ModelAdmin):
babf71ec 346 inlines = (ContratInline,)
6e7c919b 347
6e7c919b 348
babf71ec 349class TypePosteAdmin(admin.ModelAdmin):
52e05b08
OL
350 list_display = ('nom', 'famille_emploi', )
351 list_filter = ('famille_emploi', )
babf71ec 352 inlines = (PosteInline,)
6e7c919b 353
6e7c919b 354
babf71ec 355class TypeRemunerationAdmin(admin.ModelAdmin):
f7efd29a 356 list_display = ('nom', 'type_paiement', 'nature_remuneration', )
babf71ec 357 inlines = (RemunerationROInline,)
6e7c919b 358
6e7c919b 359
babf71ec
NC
360class TypeRevalorisationAdmin(admin.ModelAdmin):
361 inlines = (RemunerationROInline,)
6e7c919b 362
6e7c919b 363
babf71ec 364class ValeurPointAdmin(admin.ModelAdmin):
701f3bea
OL
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"