Supression d'une redéfinition de dossier_piece_dispatch
[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
49449367 5from django.conf import settings
d6985a3a 6from auf.django.metadata.admin import AUFMetadataAdminMixin, AUFMetadataInlineAdminMixin, AUF_METADATA_READONLY_FIELDS
babf71ec 7from project.rh import models as rh
84cbb4c5 8from forms import DossierForm, ContratForm
6e7c919b 9
d6985a3a 10# Inlines
6e7c919b 11
d6985a3a
OL
12class ReadOnlyInlineMixin(object):
13 def get_readonly_fields(self, request, obj=None):
14 return [f.name for f in self.model._meta.fields if f.name not in AUF_METADATA_READONLY_FIELDS]
6e7c919b
NC
15
16
51ab4c2c 17class AyantDroitInline(AUFMetadataInlineAdminMixin, admin.StackedInline):
babf71ec 18 model = models.Model # à remplacer dans admin.py
51ab4c2c 19 extra = 0
54d04eed 20
d6985a3a
OL
21
22class AyantDroitCommentaireInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
cf786fb2 23 readonly_fields = ('owner', )
babf71ec 24 model = models.Model # à remplacer dans admin.py
cf786fb2 25 extra = 1
6e7c919b 26
54d04eed 27
d6985a3a 28class ContratInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
84cbb4c5 29 form = ContratForm
babf71ec 30 model = models.Model # à remplacer dans admin.py
1f2979b8 31 extra = 1
babf71ec
NC
32
33
d6985a3a
OL
34class DossierROInline(ReadOnlyInlineMixin, admin.TabularInline):
35 exclude = AUF_METADATA_READONLY_FIELDS
babf71ec 36 model = models.Model # à remplacer dans admin.py
babf71ec 37
d6985a3a
OL
38
39class DossierCommentaireInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
1f2979b8 40 readonly_fields = ('owner', )
babf71ec 41 model = models.Model # à remplacer dans admin.py
1f2979b8 42 extra = 1
babf71ec 43
d6985a3a 44
babf71ec
NC
45class DossierPieceInline(admin.TabularInline):
46 model = models.Model # à remplacer dans admin.py
988af3fb 47 extra = 4
babf71ec
NC
48
49
50class EmployeInline(admin.TabularInline):
51 model = models.Model # à remplacer dans admin.py
52
d6985a3a 53class EmployeCommentaireInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
cf786fb2 54 readonly_fields = ('owner', )
babf71ec 55 model = models.Model # à remplacer dans admin.py
cf786fb2 56 extra = 1
babf71ec
NC
57
58
59class EmployePieceInline(admin.TabularInline):
60 model = models.Model # à remplacer dans admin.py
988af3fb 61 extra = 4
babf71ec
NC
62
63
d6985a3a 64class EvenementInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
babf71ec 65 model = models.Model # à remplacer dans admin.py
1f2979b8 66 extra = 1
babf71ec
NC
67
68
d6985a3a 69class EvenementRemunerationInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
babf71ec 70 model = models.Model # à remplacer dans admin.py
1f2979b8 71 extra = 1
babf71ec
NC
72
73
d6985a3a 74class PosteCommentaireInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
70561dc2 75 readonly_fields = ('owner', )
babf71ec 76 model = models.Model # à remplacer dans admin.py
70561dc2 77 extra = 1
babf71ec
NC
78
79
80class PosteFinancementInline(admin.TabularInline):
81 model = models.Model # à remplacer dans admin.py
82
83
84class PostePieceInline(admin.TabularInline):
85 model = models.Model # à remplacer dans admin.py
86
87
d6985a3a 88class RemunerationInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
babf71ec 89 model = models.Model # à remplacer dans admin.py
1f2979b8 90 extra = 1
babf71ec
NC
91
92
d6985a3a 93class RemunerationROInline(ReadOnlyInlineMixin, RemunerationInline):
6e7c919b
NC
94 pass
95
54d04eed 96
26dacccc 97class TypePosteInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
babf71ec
NC
98 model = models.Model # à remplacer dans admin.py
99
100
101# Admins
102
d6985a3a 103class AyantDroitAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
cf786fb2
OL
104 """
105 L'ajout d'un nouvel ayantdroit se fait dans l'admin de l'employé.
106 """
387ab827 107 alphabet_filter = 'nom'
cf786fb2 108 search_fields = ('nom', 'prenom', 'employe__nom', 'employe__prenom', )
1a89b1f3 109 list_display = ('_employe', 'lien_parente', '_ayantdroit', )
babf71ec 110 inlines = (AyantDroitCommentaireInline,)
d6985a3a
OL
111 readonly_fields = AUFMetadataAdminMixin.readonly_fields + ('employe',)
112 fieldsets = AUFMetadataAdminMixin.fieldsets + (
cf786fb2
OL
113 ("Lien avec l'employé", {
114 'fields': ('employe', 'lien_parente', )
115 }),
116
117 ('Identification', {
118 'fields': ('nom', 'prenom', 'nom_affichage', 'nationalite', 'date_naissance', 'genre', )
119 }),
120 )
121
122 def save_formset(self, request, form, formset, change):
123 instances = formset.save(commit=False)
124 for instance in instances:
125 if instance.__class__ == rh.AyantDroitCommentaire:
126 instance.owner = request.user
127 instance.save()
cf786fb2
OL
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
324bf312
OL
144class ClassementAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
145 fieldsets = AUFMetadataAdminMixin.fieldsets + (
146 (None, {
147 'fields': ('type', 'echelon', 'degre', 'coefficient', )
148 }),
149 )
150
6e7c919b 151
6e7c919b
NC
152class CommentaireAdmin(admin.ModelAdmin):
153 pass
154
155
84cbb4c5
OL
156#class ContratAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
157# form = ContratForm
158# alphabet_filter = 'dossier__employe__nom'
159# search_fields = ('dossier__employe__nom', 'dossier__employe__prenom', 'dossier__poste__nom', 'dossier__poste__nom_feminin', )
160# list_display = ('id', '_employe', '_poste', 'date_debut', 'date_fin', '_implantation', )
161# fieldsets = AUFMetadataAdminMixin.fieldsets + (
162# (None, {
163# 'fields': ('dossier', 'type_contrat', 'date_debut', 'date_fin', )
164# }),
165# )
166#
167# def lookup_allowed(self, key, value):
168# if key in ('dossier__employe__nom__istartswith', ):
169# return True
170#
171# def _employe(self, obj):
172# return unicode(obj.dossier.employe)
173# _employe.short_description = "Employé"
174#
175# def _poste(self, obj):
176# return obj.dossier.poste.nom
177# _poste.short_description = "Poste"
178#
179# def _implantation(self, obj):
180# return obj.dossier.poste.implantation
181# _poste.short_description = "Implantation"
54d04eed 182
84fc088b
OL
183class DeviseAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
184 fieldsets = AUFMetadataAdminMixin.fieldsets + (
185 (None, {
186 'fields': ('code', 'nom', ),
187 }),
188 )
6e7c919b 189
54d04eed 190
d6985a3a 191class DossierAdmin(AUFMetadataAdminMixin, admin.ModelAdmin,):
84cbb4c5 192 form = DossierForm
387ab827 193 alphabet_filter = 'employe__nom'
d8d7985b 194 search_fields = ('employe__nom', 'employe__prenom', 'poste__nom', 'poste__nom_feminin')
49449367 195 list_display = ('_employe', '_poste', 'date_debut', 'date_fin', '_actif')
1f2979b8 196 inlines = (DossierPieceInline, ContratInline,
cf786fb2
OL
197 RemunerationInline,
198 #EvenementInline,
199 DossierCommentaireInline,
1f2979b8 200 )
d6985a3a 201 fieldsets = AUFMetadataAdminMixin.fieldsets + (
1f2979b8
OL
202 ('Identification', {
203 'fields': ('employe', 'poste', 'statut', 'organisme_bstg',)
204 }),
205 ('Recrutement', {
206 'fields': ('remplacement', 'statut_residence', )
207 }),
208 ('Rémunération', {
209 'fields': ('classement', 'regime_travail', 'regime_travail_nb_heure_semaine',)
210 }),
211 ('Occupation du Poste par cet Employe', {
212 'fields': ('date_debut', 'date_fin', )
213 }),
214 )
54d04eed 215
387ab827 216 def lookup_allowed(self, key, value):
49449367 217 if key in ('employe__nom__istartswith', 'actif__exact', ):
387ab827
OL
218 return True
219
49449367
OL
220 def _actif(self, dossier):
221 if dossier.employe.actif:
222 html = """<img alt="True" src="%simg/admin/icon-yes.gif">"""
223 else:
224 html = """<img alt="False" src="%simg/admin/icon-no.gif">"""
225 return html % settings.ADMIN_MEDIA_PREFIX
226 _actif.allow_tags = u'Employé actif'
227 _actif.short_description = u'Employé actif'
228 _actif.admin_order_field = 'employe__actif'
387ab827 229
54d04eed
NC
230 def _poste(self, dossier):
231 return unicode(dossier.poste.nom)
232 _poste.short_description = u'Poste'
d9836879 233 _poste.admin_order_field = 'poste__nom'
54d04eed
NC
234
235 def _employe(self, dossier):
236 return unicode(dossier.employe)
237 _employe.short_description = u'Employé'
d9836879
OL
238 _employe.admin_order_field = 'employe__nom'
239
1f2979b8
OL
240 def save_formset(self, request, form, formset, change):
241 instances = formset.save(commit=False)
242 for instance in instances:
243 if instance.__class__ == rh.DossierCommentaire:
244 instance.owner = request.user
245 instance.save()
6e7c919b
NC
246
247class DossierPieceAdmin(admin.ModelAdmin):
248 pass
249
54d04eed 250
6e7c919b
NC
251class DossierCommentaireAdmin(admin.ModelAdmin):
252 pass
253
54d04eed 254
d6985a3a 255class EmployeAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
7ffc5aa4 256 alphabet_filter = 'nom'
49449367
OL
257 search_fields = ('id', 'nom', 'prenom', 'nom_affichage', 'actif', )
258 list_filter = ('actif', )
259 ordering = ('nom', )
260 actions = ('desactiver', )
261 list_display = ('nom', 'prenom', 'actif', )
babf71ec
NC
262 inlines = (AyantDroitInline,
263 DossierROInline,
264 EmployePieceInline,
265 EmployeCommentaireInline)
d6985a3a 266 fieldsets = AUFMetadataAdminMixin.fieldsets + (
cf786fb2
OL
267 ('Identification', {
268 'fields': ('nom', 'prenom', 'nom_affichage', 'nationalite', 'date_naissance', 'genre', )
269 }),
270 ('Informations personnelles', {
271 'fields': ('situation_famille', 'date_entree', )
272 }),
273 ('Coordonnées', {
274 'fields': ('tel_domicile', 'tel_cellulaire', 'adresse', 'ville', 'province', 'code_postal', 'pays', )
275 }),
276 )
babf71ec 277
cf786fb2
OL
278 def save_formset(self, request, form, formset, change):
279 instances = formset.save(commit=False)
280 for instance in instances:
281 if instance.__class__ == rh.EmployeCommentaire:
282 instance.owner = request.user
283 instance.save()
babf71ec
NC
284
285class EmployeCommentaireAdmin(admin.ModelAdmin):
6e7c919b
NC
286 pass
287
54d04eed 288
babf71ec 289class EmployePieceAdmin(admin.ModelAdmin):
6e7c919b
NC
290 pass
291
54d04eed 292
6e7c919b 293class EvenementAdmin(admin.ModelAdmin):
babf71ec 294 inlines = (EvenementRemunerationInline,)
6e7c919b 295
54d04eed 296
6e7c919b
NC
297class EvenementRemunerationAdmin(admin.ModelAdmin):
298 pass
299
54d04eed 300
26dacccc 301class FamilleEmploiAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
babf71ec 302 inlines = (TypePosteInline,)
26dacccc
OL
303 fieldsets = AUFMetadataAdminMixin.fieldsets + (
304 (None, {
305 'fields': ('nom', )
306 }),
307 )
6e7c919b 308
54d04eed 309
43f5653a 310class OrganismeBstgAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
d8d7985b 311 search_fields = ('nom', )
1c8856ef 312 list_display = ('nom', 'type', 'pays', )
babf71ec 313 inlines = (DossierROInline,)
43f5653a
OL
314 fieldsets = AUFMetadataAdminMixin.fieldsets + (
315 (None, {
316 'fields': ('nom', 'type', 'pays', )
317 }),
318 )
6e7c919b 319
54d04eed 320
d2cf315a 321class PosteAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
387ab827 322 alphabet_filter = 'nom'
70561dc2
OL
323 search_fields = ('nom', 'implantation__code', 'implantation__nom', 'implantation__region__code', 'implantation__region__nom', )
324 list_display = ('nom', 'implantation', 'service', 'type_poste', 'date_debut', 'date_fin', )
d2cf315a 325 fieldsets = AUFMetadataAdminMixin.fieldsets + (
6e7c919b
NC
326 (None, {
327 'fields': ('nom', 'nom_feminin', 'implantation', 'type_poste',
328 'service', 'responsable')
329 }),
330 ('Contrat', {
331 'fields': ('regime_travail', 'regime_travail_nb_heure_semaine')
332 }),
333 ('Recrutement', {
334 'fields': ('local', 'expatrie', 'mise_a_disposition', 'appel')
335 }),
336 ('Rémunération', {
337 'fields': ('classement_min', 'classement_max', 'valeur_point_min',
338 'valeur_point_max', 'devise_min', 'devise_max',
339 'salaire_min', 'salaire_max', 'indemn_min',
340 'indemn_max', 'autre_min', 'autre_max')
341 }),
342 ('Comparatifs de rémunération', {
343 'fields': ('devise_comparaison', 'comp_locale_min',
344 'comp_locale_max', 'comp_universite_min',
345 'comp_universite_max', 'comp_fonctionpub_min',
346 'comp_fonctionpub_max', 'comp_ong_min', 'comp_ong_max',
347 'comp_autre_min', 'comp_autre_max')
348 }),
349 ('Justification', {
350 'fields': ('justification',)
351 }),
352 ('Autres Metadata', {
353 'fields': ('date_validation', 'date_debut', 'date_fin')
354 }),
355 )
356
babf71ec
NC
357 inlines = (PosteFinancementInline,
358 PostePieceInline,
70561dc2
OL
359 DossierROInline,
360 PosteCommentaireInline, )
6e7c919b 361
70561dc2
OL
362 def save_formset(self, request, form, formset, change):
363 instances = formset.save(commit=False)
364 for instance in instances:
365 if instance.__class__ == rh.PosteCommentaire:
366 instance.owner = request.user
367 instance.save()
368 formset.save_m2m()
6e7c919b
NC
369
370class PosteCommentaireAdmin(admin.ModelAdmin):
371 pass
372
6e7c919b 373
babf71ec 374class PosteFinancementAdmin(admin.ModelAdmin):
6e7c919b
NC
375 pass
376
6e7c919b 377
babf71ec 378class PostePieceAdmin(admin.ModelAdmin):
6e7c919b
NC
379 pass
380
6e7c919b 381
babf71ec 382class RemunerationAdmin(admin.ModelAdmin):
6e7c919b
NC
383 pass
384
6e7c919b 385
1eede0db
OL
386class ResponsableImplantationAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
387 fieldsets = AUFMetadataAdminMixin.fieldsets + (
388 (None, {
389 'fields': ('employe', 'implantation', ),
390 }),
391 )
392
6e7c919b 393
43f5653a
OL
394class ServiceAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
395 list_display = ('nom', 'actif', )
396 fieldsets = AUFMetadataAdminMixin.fieldsets + (
397 (None, {
398 'fields': ('nom', ),
399 }),
400 )
6e7c919b 401
43f5653a
OL
402class StatutAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
403 fieldsets = AUFMetadataAdminMixin.fieldsets + (
404 (None, {
405 'fields': ('code', 'nom', ),
406 }),
407 )
6e7c919b 408
babf71ec 409class TauxChangeAdmin(admin.ModelAdmin):
24475cf1
OL
410 list_display = ('taux', 'devise', 'annee', )
411 list_filter = ('devise', )
dcbadfad
OL
412 fieldsets = AUFMetadataAdminMixin.fieldsets + (
413 (None, {
414 'fields': ('taux', 'devise', 'annee', ),
415 }),
416 )
6e7c919b 417
6e7c919b 418class TypeContratAdmin(admin.ModelAdmin):
babf71ec 419 inlines = (ContratInline,)
6e7c919b 420
6e7c919b 421
240893cb 422class TypePosteAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
d8d7985b 423 search_fields = ('nom', 'nom_feminin', )
52e05b08
OL
424 list_display = ('nom', 'famille_emploi', )
425 list_filter = ('famille_emploi', )
240893cb
OL
426 fieldsets = AUFMetadataAdminMixin.fieldsets + (
427 (None, {
428 'fields': ('nom', 'nom_feminin', 'is_responsable', 'famille_emploi', )
429 }),
430 )
6e7c919b 431
6e7c919b 432
3f486b41 433class TypeRemunerationAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
f7efd29a 434 list_display = ('nom', 'type_paiement', 'nature_remuneration', )
3f486b41
OL
435 #inlines = (RemunerationROInline,) utilité?
436 fieldsets = AUFMetadataAdminMixin.fieldsets + (
437 (None, {
438 'fields': ('nom', 'type_paiement', 'nature_remuneration', )
439 }),
440 )
6e7c919b 441
6e7c919b 442
3f486b41
OL
443class TypeRevalorisationAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
444 #inlines = (RemunerationROInline,) utilité?
445 fieldsets = AUFMetadataAdminMixin.fieldsets + (
446 (None, {
447 'fields': ('nom', )
448 }),
449 )
6e7c919b 450
6e7c919b 451
84fc088b 452class ValeurPointAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
701f3bea 453 list_display = ('_devise_code', '_devise_nom', 'annee', 'valeur', )
84fc088b
OL
454 fieldsets = AUFMetadataAdminMixin.fieldsets + (
455 (None, {
456 'fields': ('valeur', 'devise', 'implantation', 'annee', )
457 }),
458 )
701f3bea
OL
459
460 def _devise_code(self, obj):
461 return obj.devise.code
462 _devise_code.short_description = "Code de la devise"
463
464 def _devise_nom(self, obj):
465 return obj.devise.nom
466 _devise_nom.short_description = "Nom de la devise"