Commit | Line | Data |
---|---|---|
6e7c919b NC |
1 | # -*- encoding: utf-8 -*- |
2 | ||
8d3e2fff PP |
3 | from collections import defaultdict |
4 | import datetime | |
5 | ||
babf71ec | 6 | from django.db import models |
cb527994 | 7 | from django import forms |
790b9793 | 8 | from django.core.urlresolvers import reverse |
6e7c919b | 9 | from django.contrib import admin |
49449367 | 10 | from django.conf import settings |
aff1a4c6 | 11 | from django.db.models import Q |
105dd778 | 12 | from ajax_select import make_ajax_form |
d6985a3a | 13 | from auf.django.metadata.admin import AUFMetadataAdminMixin, AUFMetadataInlineAdminMixin, AUF_METADATA_READONLY_FIELDS |
babf71ec | 14 | from project.rh import models as rh |
0b0545bd | 15 | from forms import ContratForm, AyantDroitForm, EmployeAdminForm, AjaxSelect |
aff1a4c6 PP |
16 | from dae.utils import get_employe_from_user |
17 | ||
18 | ||
1c08b5b5 OL |
19 | # Desactivation des bactch action a cause des managers qui delete |
20 | AUFMetadataAdminMixin.actions = None | |
cb527994 | 21 | |
6318ebea PP |
22 | # Override of the InlineModelAdmin to support the link in the tabular inline |
23 | class LinkedInline(admin.options.InlineModelAdmin): | |
24 | template = "admin/linked.html" | |
25 | admin_model_path = None | |
26 | ||
27 | def __init__(self, *args): | |
28 | super(LinkedInline, self).__init__(*args) | |
29 | if self.admin_model_path is None: | |
30 | self.admin_model_path = self.model.__name__.lower() | |
31 | ||
32 | ||
aff1a4c6 PP |
33 | class ProtectRegionMixin(object): |
34 | ||
35 | def queryset(self, request): | |
32373f2e | 36 | from dae.workflow import grp_drh, grp_correspondants_rh |
aff1a4c6 PP |
37 | qs = super(ProtectRegionMixin, self).queryset(request) |
38 | ||
39 | if request.user.is_superuser: | |
40 | return qs | |
41 | ||
32373f2e | 42 | user_groups = request.user.groups.all() |
aff1a4c6 | 43 | |
32373f2e OL |
44 | if grp_drh in user_groups: |
45 | return qs | |
46 | ||
47 | if grp_correspondants_rh in user_groups: | |
48 | employe = get_employe_from_user(request.user) | |
49 | q = Q(**{self.model.prefix_implantation: employe.implantation.region}) | |
50 | qs = qs.filter(q).distinct() | |
51 | return qs | |
52 | return qs.none() | |
aff1a4c6 PP |
53 | |
54 | def has_change_permission(self, request, obj=None): | |
02e6b741 | 55 | if obj is None: |
aff1a4c6 | 56 | return True |
02e6b741 OL |
57 | ids = [o.id for o in self.queryset(request)] |
58 | return obj.id in ids | |
aff1a4c6 | 59 | |
6e7c919b | 60 | |
d6985a3a | 61 | # Inlines |
6e7c919b | 62 | |
d6985a3a OL |
63 | class ReadOnlyInlineMixin(object): |
64 | def get_readonly_fields(self, request, obj=None): | |
65 | return [f.name for f in self.model._meta.fields if f.name not in AUF_METADATA_READONLY_FIELDS] | |
6e7c919b NC |
66 | |
67 | ||
51ab4c2c | 68 | class AyantDroitInline(AUFMetadataInlineAdminMixin, admin.StackedInline): |
babf71ec | 69 | model = models.Model # à remplacer dans admin.py |
cf022e27 | 70 | form = AyantDroitForm |
51ab4c2c | 71 | extra = 0 |
54d04eed | 72 | |
972f50e4 PP |
73 | fieldsets = ( |
74 | (None, { | |
75 | 'fields': (('nom', 'prenom'), ('nom_affichage', 'genre'), 'nationalite', 'date_naissance', 'lien_parente', ) | |
76 | }), | |
77 | ) | |
78 | ||
d6985a3a OL |
79 | |
80 | class AyantDroitCommentaireInline(AUFMetadataInlineAdminMixin, admin.TabularInline): | |
cf786fb2 | 81 | readonly_fields = ('owner', ) |
babf71ec | 82 | model = models.Model # à remplacer dans admin.py |
cf786fb2 | 83 | extra = 1 |
6e7c919b | 84 | |
54d04eed | 85 | |
d6985a3a | 86 | class ContratInline(AUFMetadataInlineAdminMixin, admin.TabularInline): |
84cbb4c5 | 87 | form = ContratForm |
babf71ec | 88 | model = models.Model # à remplacer dans admin.py |
1f2979b8 | 89 | extra = 1 |
babf71ec NC |
90 | |
91 | ||
6318ebea | 92 | class DossierROInline(ReadOnlyInlineMixin, LinkedInline): |
3ebc0952 | 93 | template = "admin/rh/dossier/linked.html" |
d6985a3a | 94 | exclude = AUF_METADATA_READONLY_FIELDS |
babf71ec | 95 | model = models.Model # à remplacer dans admin.py |
54773196 | 96 | extra = 0 |
52688246 OL |
97 | can_delete = False |
98 | ||
0e190851 | 99 | def has_add_permission(self, request=None): |
52688246 OL |
100 | return False |
101 | ||
102 | def has_change_permission(self, request, obj=None): | |
103 | return False | |
104 | ||
105 | def has_delete_permission(self, request, obj=None): | |
106 | return False | |
babf71ec | 107 | |
d6985a3a OL |
108 | |
109 | class DossierCommentaireInline(AUFMetadataInlineAdminMixin, admin.TabularInline): | |
1f2979b8 | 110 | readonly_fields = ('owner', ) |
babf71ec | 111 | model = models.Model # à remplacer dans admin.py |
1f2979b8 | 112 | extra = 1 |
babf71ec | 113 | |
d6985a3a | 114 | |
babf71ec NC |
115 | class DossierPieceInline(admin.TabularInline): |
116 | model = models.Model # à remplacer dans admin.py | |
988af3fb | 117 | extra = 4 |
babf71ec NC |
118 | |
119 | ||
120 | class EmployeInline(admin.TabularInline): | |
121 | model = models.Model # à remplacer dans admin.py | |
122 | ||
d6985a3a | 123 | class EmployeCommentaireInline(AUFMetadataInlineAdminMixin, admin.TabularInline): |
cf786fb2 | 124 | readonly_fields = ('owner', ) |
babf71ec | 125 | model = models.Model # à remplacer dans admin.py |
cf786fb2 | 126 | extra = 1 |
babf71ec NC |
127 | |
128 | ||
129 | class EmployePieceInline(admin.TabularInline): | |
130 | model = models.Model # à remplacer dans admin.py | |
988af3fb | 131 | extra = 4 |
babf71ec NC |
132 | |
133 | ||
d6985a3a | 134 | class EvenementInline(AUFMetadataInlineAdminMixin, admin.TabularInline): |
babf71ec | 135 | model = models.Model # à remplacer dans admin.py |
1f2979b8 | 136 | extra = 1 |
babf71ec NC |
137 | |
138 | ||
d6985a3a | 139 | class EvenementRemunerationInline(AUFMetadataInlineAdminMixin, admin.TabularInline): |
babf71ec | 140 | model = models.Model # à remplacer dans admin.py |
1f2979b8 | 141 | extra = 1 |
babf71ec NC |
142 | |
143 | ||
d6985a3a | 144 | class PosteCommentaireInline(AUFMetadataInlineAdminMixin, admin.TabularInline): |
70561dc2 | 145 | readonly_fields = ('owner', ) |
babf71ec | 146 | model = models.Model # à remplacer dans admin.py |
70561dc2 | 147 | extra = 1 |
babf71ec NC |
148 | |
149 | ||
150 | class PosteFinancementInline(admin.TabularInline): | |
151 | model = models.Model # à remplacer dans admin.py | |
152 | ||
153 | ||
154 | class PostePieceInline(admin.TabularInline): | |
155 | model = models.Model # à remplacer dans admin.py | |
156 | ||
157 | ||
d6985a3a | 158 | class RemunerationInline(AUFMetadataInlineAdminMixin, admin.TabularInline): |
babf71ec | 159 | model = models.Model # à remplacer dans admin.py |
1f2979b8 | 160 | extra = 1 |
babf71ec NC |
161 | |
162 | ||
d6985a3a | 163 | class RemunerationROInline(ReadOnlyInlineMixin, RemunerationInline): |
6e7c919b NC |
164 | pass |
165 | ||
54d04eed | 166 | |
26dacccc | 167 | class TypePosteInline(AUFMetadataInlineAdminMixin, admin.TabularInline): |
babf71ec NC |
168 | model = models.Model # à remplacer dans admin.py |
169 | ||
170 | ||
171 | # Admins | |
172 | ||
aff1a4c6 | 173 | class AyantDroitAdmin(AUFMetadataAdminMixin, ProtectRegionMixin, admin.ModelAdmin): |
cf786fb2 OL |
174 | """ |
175 | L'ajout d'un nouvel ayantdroit se fait dans l'admin de l'employé. | |
176 | """ | |
387ab827 | 177 | alphabet_filter = 'nom' |
cf786fb2 | 178 | search_fields = ('nom', 'prenom', 'employe__nom', 'employe__prenom', ) |
1a89b1f3 | 179 | list_display = ('_employe', 'lien_parente', '_ayantdroit', ) |
babf71ec | 180 | inlines = (AyantDroitCommentaireInline,) |
d6985a3a OL |
181 | readonly_fields = AUFMetadataAdminMixin.readonly_fields + ('employe',) |
182 | fieldsets = AUFMetadataAdminMixin.fieldsets + ( | |
cf786fb2 | 183 | ("Lien avec l'employé", { |
76e26dfc | 184 | 'fields': (('employe', 'lien_parente'), ) |
cf786fb2 OL |
185 | }), |
186 | ||
187 | ('Identification', { | |
76e26dfc | 188 | 'fields': (('nom', 'prenom'), ('nom_affichage', 'genre'), 'nationalite', 'date_naissance', ) |
cf786fb2 OL |
189 | }), |
190 | ) | |
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.AyantDroitCommentaire: | |
196 | instance.owner = request.user | |
197 | instance.save() | |
cf786fb2 OL |
198 | |
199 | def _ayantdroit(self, obj): | |
200 | return unicode(obj) | |
201 | _ayantdroit.short_description = u'Ayant droit' | |
babf71ec | 202 | |
cf786fb2 OL |
203 | def _employe(self, obj): |
204 | return unicode(obj.employe) | |
205 | _employe.short_description = u'Employé' | |
206 | ||
207 | def has_add_permission(self, request): | |
208 | return False | |
babf71ec NC |
209 | |
210 | class AyantDroitCommentaireAdmin(admin.ModelAdmin): | |
6e7c919b NC |
211 | pass |
212 | ||
54d04eed | 213 | |
324bf312 OL |
214 | class ClassementAdmin(AUFMetadataAdminMixin, admin.ModelAdmin): |
215 | fieldsets = AUFMetadataAdminMixin.fieldsets + ( | |
216 | (None, { | |
217 | 'fields': ('type', 'echelon', 'degre', 'coefficient', ) | |
218 | }), | |
219 | ) | |
220 | ||
6e7c919b | 221 | |
6e7c919b NC |
222 | class CommentaireAdmin(admin.ModelAdmin): |
223 | pass | |
224 | ||
225 | ||
84cbb4c5 OL |
226 | #class ContratAdmin(AUFMetadataAdminMixin, admin.ModelAdmin): |
227 | # form = ContratForm | |
228 | # alphabet_filter = 'dossier__employe__nom' | |
229 | # search_fields = ('dossier__employe__nom', 'dossier__employe__prenom', 'dossier__poste__nom', 'dossier__poste__nom_feminin', ) | |
230 | # list_display = ('id', '_employe', '_poste', 'date_debut', 'date_fin', '_implantation', ) | |
231 | # fieldsets = AUFMetadataAdminMixin.fieldsets + ( | |
232 | # (None, { | |
233 | # 'fields': ('dossier', 'type_contrat', 'date_debut', 'date_fin', ) | |
234 | # }), | |
235 | # ) | |
236 | # | |
237 | # def lookup_allowed(self, key, value): | |
238 | # if key in ('dossier__employe__nom__istartswith', ): | |
239 | # return True | |
240 | # | |
241 | # def _employe(self, obj): | |
242 | # return unicode(obj.dossier.employe) | |
243 | # _employe.short_description = "Employé" | |
244 | # | |
245 | # def _poste(self, obj): | |
246 | # return obj.dossier.poste.nom | |
247 | # _poste.short_description = "Poste" | |
248 | # | |
249 | # def _implantation(self, obj): | |
250 | # return obj.dossier.poste.implantation | |
251 | # _poste.short_description = "Implantation" | |
54d04eed | 252 | |
84fc088b OL |
253 | class DeviseAdmin(AUFMetadataAdminMixin, admin.ModelAdmin): |
254 | fieldsets = AUFMetadataAdminMixin.fieldsets + ( | |
255 | (None, { | |
256 | 'fields': ('code', 'nom', ), | |
257 | }), | |
258 | ) | |
6e7c919b | 259 | |
54d04eed | 260 | |
0b0545bd | 261 | class DossierAdmin(AUFMetadataAdminMixin, ProtectRegionMixin, admin.ModelAdmin, AjaxSelect): |
387ab827 | 262 | alphabet_filter = 'employe__nom' |
d8d7985b | 263 | search_fields = ('employe__nom', 'employe__prenom', 'poste__nom', 'poste__nom_feminin') |
150d83ec | 264 | list_display = ('_id', '_employe', '_actif', '_poste', 'date_debut', 'date_fin', 'date_modification') |
46d4c28a OL |
265 | list_filter = ( |
266 | 'poste__implantation__region', | |
267 | 'poste__implantation', | |
268 | 'poste__type_poste', | |
269 | 'poste__type_poste__famille_emploi', | |
270 | ) | |
1f2979b8 | 271 | inlines = (DossierPieceInline, ContratInline, |
cf786fb2 OL |
272 | RemunerationInline, |
273 | #EvenementInline, | |
274 | DossierCommentaireInline, | |
1f2979b8 | 275 | ) |
d6985a3a | 276 | fieldsets = AUFMetadataAdminMixin.fieldsets + ( |
5961a2c9 | 277 | (None, { |
7ac30609 | 278 | 'fields': ('employe', 'poste', 'statut', 'organisme_bstg',) |
1f2979b8 OL |
279 | }), |
280 | ('Recrutement', { | |
7c182958 | 281 | 'fields': ('statut_residence', 'remplacement', 'remplacement_de', ) |
1f2979b8 OL |
282 | }), |
283 | ('Rémunération', { | |
cb962802 | 284 | 'fields': ('classement', ('regime_travail', 'regime_travail_nb_heure_semaine'),) |
1f2979b8 OL |
285 | }), |
286 | ('Occupation du Poste par cet Employe', { | |
cb962802 | 287 | 'fields': (('date_debut', 'date_fin'), ) |
1f2979b8 OL |
288 | }), |
289 | ) | |
0b0545bd OL |
290 | form = make_ajax_form(rh.Dossier, { |
291 | 'employe' : 'employes', | |
292 | 'poste' : 'postes', | |
293 | 'remplacement_de' : 'dossiers', | |
294 | }) | |
7c182958 | 295 | |
387ab827 | 296 | def lookup_allowed(self, key, value): |
150d83ec OL |
297 | if key in ( |
298 | 'employe__nom__istartswith', | |
299 | 'actif__exact', | |
b4c7b7ca OL |
300 | 'poste__implantation__region__id__exact', |
301 | 'poste__implantation__id__exact', | |
46d4c28a OL |
302 | 'poste__type_poste__id__exact', |
303 | 'poste__type_poste__famille_emploi__id__exact', | |
150d83ec | 304 | ): |
387ab827 OL |
305 | return True |
306 | ||
150d83ec OL |
307 | def _id(self, d): |
308 | link = u"""<a onclick="return showAddAnotherPopup(this);" href='%s'>%s</a> <a href="%s" title="Modifier le dossier"><img src="%simg/page_edit.png" /></a>""" % \ | |
309 | (reverse('dossier_apercu', args=(d.id,)), | |
310 | d.id, | |
311 | reverse('admin:rh_dossier_change', args=(d.id,)), | |
312 | settings.MEDIA_URL, | |
313 | ) | |
314 | return link | |
315 | _id.allow_tags = True | |
316 | _id.short_description = u'Numéro de dossier' | |
317 | _id.admin_order_field = 'id' | |
318 | ||
319 | ||
49449367 OL |
320 | def _actif(self, dossier): |
321 | if dossier.employe.actif: | |
322 | html = """<img alt="True" src="%simg/admin/icon-yes.gif">""" | |
323 | else: | |
324 | html = """<img alt="False" src="%simg/admin/icon-no.gif">""" | |
325 | return html % settings.ADMIN_MEDIA_PREFIX | |
150d83ec | 326 | _actif.allow_tags = True |
49449367 OL |
327 | _actif.short_description = u'Employé actif' |
328 | _actif.admin_order_field = 'employe__actif' | |
387ab827 | 329 | |
54d04eed | 330 | def _poste(self, dossier): |
150d83ec OL |
331 | link = u"""<a onclick="return showAddAnotherPopup(this);" href='%s'>%s</a> <a href="%s" title="Modifier le poste"><img src="%simg/page_edit.png" /></a>""" % \ |
332 | (reverse('poste_apercu', args=(dossier.poste.id,)), | |
333 | dossier.poste, | |
334 | reverse('admin:rh_poste_change', args=(dossier.poste.id,)), | |
335 | settings.MEDIA_URL, | |
336 | ) | |
337 | return link | |
338 | _poste.allow_tags = True | |
54d04eed | 339 | _poste.short_description = u'Poste' |
d9836879 | 340 | _poste.admin_order_field = 'poste__nom' |
54d04eed | 341 | |
150d83ec OL |
342 | def _employe(self, obj): |
343 | employe = obj.employe | |
344 | view_link = reverse('employe_apercu', args=(employe.id,)) | |
345 | edit_link = reverse('admin:rh_employe_change', args=(employe.id,)) | |
346 | return u"""<a onclick="return showAddAnotherPopup(this);" href='%s'>[%s] %s %s</a> | |
347 | <a href="%s" title="Modifier l'employé"><img src="%simg/user_edit.png" /></a>""" % \ | |
348 | (view_link, employe.id, employe.nom.upper(), employe.prenom.title(), edit_link, settings.MEDIA_URL,) | |
349 | _employe.allow_tags = True | |
350 | _employe.short_description = u"Employé ([code] NOM Prénom)" | |
351 | _employe.admin_order_field = "employe__nom" | |
d9836879 | 352 | |
1f2979b8 OL |
353 | def save_formset(self, request, form, formset, change): |
354 | instances = formset.save(commit=False) | |
355 | for instance in instances: | |
356 | if instance.__class__ == rh.DossierCommentaire: | |
357 | instance.owner = request.user | |
358 | instance.save() | |
6e7c919b | 359 | |
8d3e2fff | 360 | |
6e7c919b NC |
361 | class DossierPieceAdmin(admin.ModelAdmin): |
362 | pass | |
363 | ||
54d04eed | 364 | |
6e7c919b NC |
365 | class DossierCommentaireAdmin(admin.ModelAdmin): |
366 | pass | |
367 | ||
54d04eed | 368 | |
aff1a4c6 | 369 | class EmployeAdmin(AUFMetadataAdminMixin, ProtectRegionMixin, admin.ModelAdmin): |
7ffc5aa4 | 370 | alphabet_filter = 'nom' |
2a333057 | 371 | DEFAULT_ALPHABET = u'ABCDEFGHIJKLMNOPQRSTUVWXYZ' |
64721a83 | 372 | search_fields = ('id', 'nom', 'prenom', 'nom_affichage', ) |
49449367 | 373 | ordering = ('nom', ) |
cb527994 | 374 | form = EmployeAdminForm |
4a1f2ece | 375 | list_display = ('_nom', '_dossiers', 'date_modification', 'user_modification',) |
16b1454e | 376 | list_filter = ('rh_dossiers__poste__implantation__region', 'rh_dossiers__poste__implantation', 'actif', ) |
babf71ec NC |
377 | inlines = (AyantDroitInline, |
378 | DossierROInline, | |
379 | EmployePieceInline, | |
380 | EmployeCommentaireInline) | |
64721a83 | 381 | fieldsets = AUFMetadataAdminMixin.fieldsets + ( |
cf786fb2 | 382 | ('Identification', { |
e35610f5 | 383 | 'fields': (('nom', 'prenom'), ('nom_affichage', 'genre'), 'nationalite', 'date_naissance', ) |
cf786fb2 OL |
384 | }), |
385 | ('Informations personnelles', { | |
386 | 'fields': ('situation_famille', 'date_entree', ) | |
387 | }), | |
388 | ('Coordonnées', { | |
e35610f5 | 389 | 'fields': (('tel_domicile', 'tel_cellulaire'), ('adresse', 'ville'), ('code_postal', 'province'), 'pays', ) |
cf786fb2 OL |
390 | }), |
391 | ) | |
babf71ec | 392 | |
4a1f2ece OL |
393 | def _nom(self, obj): |
394 | view_link = reverse('employe_apercu', args=(obj.id,)) | |
395 | edit_link = reverse('admin:rh_employe_change', args=(obj.id,)) | |
396 | return u"""<a onclick="return showAddAnotherPopup(this);" href='%s'>[%s] %s %s</a> | |
397 | <a href="%s" title="Modifier l'employé"><img src="%simg/user_edit.png" /></a>""" % \ | |
398 | (view_link, obj.id, obj.nom.upper(), obj.prenom.title(), edit_link, settings.MEDIA_URL,) | |
399 | _nom.allow_tags = True | |
400 | _nom.short_description = u"Employé ([code] NOM Prénom)" | |
401 | _nom.admin_order_field = "nom" | |
402 | ||
790b9793 OL |
403 | def _dossiers(self, obj): |
404 | l = [] | |
405 | for d in obj.dossiers.all().order_by('-date_debut'): | |
3ebc0952 OL |
406 | style = "" |
407 | if d.date_fin is not None: | |
408 | style = "color: grey"; | |
4a1f2ece | 409 | link = u"""<li><a style="%s;" onclick="return showAddAnotherPopup(this);" href='%s'>%s : %s</a> <a href="%s" title="Modifier le dossier"><img src="%simg/page_edit.png" /></a> </li>""" % \ |
3ebc0952 OL |
410 | (style, |
411 | reverse('dossier_apercu', args=(d.id,)), | |
790b9793 | 412 | d.date_debut.year, |
4a1f2ece OL |
413 | d.poste, |
414 | reverse('admin:rh_dossier_change', args=(d.id,)), | |
415 | settings.MEDIA_URL, | |
416 | ) | |
790b9793 OL |
417 | l.append(link) |
418 | return "<ul>%s</ul>" % "\n".join(l) | |
419 | _dossiers.allow_tags = True | |
420 | ||
64721a83 | 421 | def queryset(self, request): |
7eb1ab09 | 422 | qs = super(EmployeAdmin, self).queryset(request) |
2a333057 | 423 | return qs.filter(actif=True).select_related(depth=1).order_by('nom') |
64721a83 | 424 | |
cf786fb2 OL |
425 | def save_formset(self, request, form, formset, change): |
426 | instances = formset.save(commit=False) | |
427 | for instance in instances: | |
428 | if instance.__class__ == rh.EmployeCommentaire: | |
429 | instance.owner = request.user | |
430 | instance.save() | |
babf71ec | 431 | |
2d5533ac PP |
432 | |
433 | ||
babf71ec | 434 | class EmployeCommentaireAdmin(admin.ModelAdmin): |
6e7c919b NC |
435 | pass |
436 | ||
54d04eed | 437 | |
babf71ec | 438 | class EmployePieceAdmin(admin.ModelAdmin): |
6e7c919b NC |
439 | pass |
440 | ||
54d04eed | 441 | |
6e7c919b | 442 | class EvenementAdmin(admin.ModelAdmin): |
babf71ec | 443 | inlines = (EvenementRemunerationInline,) |
6e7c919b | 444 | |
54d04eed | 445 | |
6e7c919b NC |
446 | class EvenementRemunerationAdmin(admin.ModelAdmin): |
447 | pass | |
448 | ||
54d04eed | 449 | |
26dacccc | 450 | class FamilleEmploiAdmin(AUFMetadataAdminMixin, admin.ModelAdmin): |
babf71ec | 451 | inlines = (TypePosteInline,) |
26dacccc OL |
452 | fieldsets = AUFMetadataAdminMixin.fieldsets + ( |
453 | (None, { | |
454 | 'fields': ('nom', ) | |
455 | }), | |
456 | ) | |
6e7c919b | 457 | |
54d04eed | 458 | |
aff1a4c6 | 459 | class OrganismeBstgAdmin(AUFMetadataAdminMixin, ProtectRegionMixin, admin.ModelAdmin): |
d8d7985b | 460 | search_fields = ('nom', ) |
1c8856ef | 461 | list_display = ('nom', 'type', 'pays', ) |
babf71ec | 462 | inlines = (DossierROInline,) |
43f5653a OL |
463 | fieldsets = AUFMetadataAdminMixin.fieldsets + ( |
464 | (None, { | |
465 | 'fields': ('nom', 'type', 'pays', ) | |
466 | }), | |
467 | ) | |
6e7c919b | 468 | |
54d04eed | 469 | |
105dd778 OL |
470 | class PosteAdmin(AUFMetadataAdminMixin, ProtectRegionMixin, admin.ModelAdmin, AjaxSelect): |
471 | form = make_ajax_form(rh.Poste, { | |
472 | 'implantation' : 'implantations', | |
473 | 'type_poste' : 'typepostes', | |
474 | 'responsable' : 'postes', | |
475 | 'valeur_point_min' : 'valeurpoints', | |
476 | 'valeur_point_max' : 'valeurpoints', | |
477 | }) | |
387ab827 | 478 | alphabet_filter = 'nom' |
23102192 DB |
479 | search_fields = ('nom', |
480 | 'implantation__code', | |
481 | 'implantation__nom', | |
482 | 'implantation__region__code', | |
483 | 'implantation__region__nom', | |
484 | ) | |
150d83ec OL |
485 | list_display = ( |
486 | '_nom', | |
23102192 DB |
487 | '_occupe_par', |
488 | 'implantation', | |
489 | 'service', | |
23102192 DB |
490 | 'date_debut', |
491 | 'date_fin', | |
492 | 'date_modification', | |
493 | 'user_modification', | |
494 | ) | |
495 | list_filter = ('service', | |
496 | 'implantation__region', | |
23102192 | 497 | 'implantation', |
3f7e5601 | 498 | 'type_poste', |
82b41775 | 499 | 'type_poste__famille_emploi', |
23102192 | 500 | ) |
d2cf315a | 501 | fieldsets = AUFMetadataAdminMixin.fieldsets + ( |
6e7c919b | 502 | (None, { |
4497b3cb | 503 | 'fields': (('nom', 'nom_feminin'), 'implantation', 'type_poste', |
6e7c919b NC |
504 | 'service', 'responsable') |
505 | }), | |
506 | ('Contrat', { | |
4497b3cb | 507 | 'fields': (('regime_travail', 'regime_travail_nb_heure_semaine'), ) |
6e7c919b NC |
508 | }), |
509 | ('Recrutement', { | |
4497b3cb | 510 | 'fields': (('local', 'expatrie', 'mise_a_disposition', 'appel'),) |
6e7c919b NC |
511 | }), |
512 | ('Rémunération', { | |
4497b3cb PP |
513 | 'fields': (('classement_min', 'classement_max'), |
514 | ('valeur_point_min', 'valeur_point_max'), | |
515 | ('devise_min', 'devise_max'), | |
516 | ('salaire_min', 'salaire_max'), | |
517 | ('indemn_min', 'indemn_max'), | |
518 | ('autre_min', 'autre_max')) | |
6e7c919b NC |
519 | }), |
520 | ('Comparatifs de rémunération', { | |
4497b3cb PP |
521 | 'fields': ('devise_comparaison', |
522 | ('comp_locale_min', 'comp_locale_max'), | |
523 | ('comp_universite_min', 'comp_universite_max'), | |
524 | ('comp_fonctionpub_min', 'comp_fonctionpub_max'), | |
525 | ('comp_ong_min', 'comp_ong_max'), | |
526 | ('comp_autre_min', 'comp_autre_max')) | |
6e7c919b NC |
527 | }), |
528 | ('Justification', { | |
529 | 'fields': ('justification',) | |
530 | }), | |
531 | ('Autres Metadata', { | |
1c08b5b5 | 532 | 'fields': ('date_debut', 'date_fin') |
6e7c919b NC |
533 | }), |
534 | ) | |
535 | ||
babf71ec NC |
536 | inlines = (PosteFinancementInline, |
537 | PostePieceInline, | |
70561dc2 OL |
538 | DossierROInline, |
539 | PosteCommentaireInline, ) | |
6e7c919b | 540 | |
105dd778 | 541 | |
150d83ec OL |
542 | def _nom(self, poste): |
543 | link = u"""<a onclick="return showAddAnotherPopup(this);" href='%s'>%s</a> <a href="%s" title="Modifier le poste"><img src="%simg/page_edit.png" /></a>""" % \ | |
544 | (reverse('poste_apercu', args=(poste.id,)), | |
545 | poste.nom, | |
546 | reverse('admin:rh_poste_change', args=(poste.id,)), | |
547 | settings.MEDIA_URL, | |
548 | ) | |
549 | return link | |
550 | _nom.allow_tags = True | |
551 | _nom.short_description = u'Nom' | |
552 | _nom.admin_order_field = 'nom' | |
553 | ||
23102192 DB |
554 | def _occupe_par(self, obj): |
555 | """Formatte la méthode Poste.occupe_par() pour l'admin""" | |
556 | output = "VACANT" | |
557 | employes = obj.occupe_par() | |
558 | if employes: | |
559 | l = [] | |
560 | for e in employes: | |
561 | link = "<a href='%s'>%s</a>" % \ | |
562 | (reverse('admin:rh_employe_change', args=(e.id,)), | |
563 | e) | |
564 | l.append(link) | |
565 | output = "\n<br />".join(l) | |
566 | return output | |
567 | _occupe_par.allow_tags = True | |
568 | _occupe_par.short_description = "Occupé par" | |
569 | ||
70561dc2 OL |
570 | def save_formset(self, request, form, formset, change): |
571 | instances = formset.save(commit=False) | |
572 | for instance in instances: | |
573 | if instance.__class__ == rh.PosteCommentaire: | |
574 | instance.owner = request.user | |
575 | instance.save() | |
576 | formset.save_m2m() | |
6e7c919b | 577 | |
aff1a4c6 | 578 | |
6e7c919b NC |
579 | class PosteCommentaireAdmin(admin.ModelAdmin): |
580 | pass | |
581 | ||
6e7c919b | 582 | |
babf71ec | 583 | class PosteFinancementAdmin(admin.ModelAdmin): |
6e7c919b NC |
584 | pass |
585 | ||
6e7c919b | 586 | |
babf71ec | 587 | class PostePieceAdmin(admin.ModelAdmin): |
a184c555 | 588 | fk_name = 'poste' |
6e7c919b | 589 | |
6e7c919b | 590 | |
babf71ec | 591 | class RemunerationAdmin(admin.ModelAdmin): |
6e7c919b NC |
592 | pass |
593 | ||
6e7c919b | 594 | |
1eede0db OL |
595 | class ResponsableImplantationAdmin(AUFMetadataAdminMixin, admin.ModelAdmin): |
596 | fieldsets = AUFMetadataAdminMixin.fieldsets + ( | |
597 | (None, { | |
598 | 'fields': ('employe', 'implantation', ), | |
599 | }), | |
600 | ) | |
601 | ||
6e7c919b | 602 | |
43f5653a OL |
603 | class ServiceAdmin(AUFMetadataAdminMixin, admin.ModelAdmin): |
604 | list_display = ('nom', 'actif', ) | |
605 | fieldsets = AUFMetadataAdminMixin.fieldsets + ( | |
606 | (None, { | |
607 | 'fields': ('nom', ), | |
608 | }), | |
609 | ) | |
6e7c919b | 610 | |
43f5653a OL |
611 | class StatutAdmin(AUFMetadataAdminMixin, admin.ModelAdmin): |
612 | fieldsets = AUFMetadataAdminMixin.fieldsets + ( | |
613 | (None, { | |
614 | 'fields': ('code', 'nom', ), | |
615 | }), | |
616 | ) | |
6e7c919b | 617 | |
babf71ec | 618 | class TauxChangeAdmin(admin.ModelAdmin): |
24475cf1 OL |
619 | list_display = ('taux', 'devise', 'annee', ) |
620 | list_filter = ('devise', ) | |
dcbadfad OL |
621 | fieldsets = AUFMetadataAdminMixin.fieldsets + ( |
622 | (None, { | |
623 | 'fields': ('taux', 'devise', 'annee', ), | |
624 | }), | |
625 | ) | |
6e7c919b | 626 | |
6e7c919b | 627 | class TypeContratAdmin(admin.ModelAdmin): |
babf71ec | 628 | inlines = (ContratInline,) |
7376afeb PP |
629 | fieldsets = AUFMetadataAdminMixin.fieldsets + ( |
630 | (None, { | |
631 | 'fields': ('nom', 'nom_long', ), | |
632 | }), | |
633 | ) | |
6e7c919b | 634 | |
6e7c919b | 635 | |
240893cb | 636 | class TypePosteAdmin(AUFMetadataAdminMixin, admin.ModelAdmin): |
d8d7985b | 637 | search_fields = ('nom', 'nom_feminin', ) |
52e05b08 OL |
638 | list_display = ('nom', 'famille_emploi', ) |
639 | list_filter = ('famille_emploi', ) | |
240893cb OL |
640 | fieldsets = AUFMetadataAdminMixin.fieldsets + ( |
641 | (None, { | |
642 | 'fields': ('nom', 'nom_feminin', 'is_responsable', 'famille_emploi', ) | |
643 | }), | |
644 | ) | |
6e7c919b | 645 | |
6e7c919b | 646 | |
3f486b41 | 647 | class TypeRemunerationAdmin(AUFMetadataAdminMixin, admin.ModelAdmin): |
f7efd29a | 648 | list_display = ('nom', 'type_paiement', 'nature_remuneration', ) |
3f486b41 OL |
649 | #inlines = (RemunerationROInline,) utilité? |
650 | fieldsets = AUFMetadataAdminMixin.fieldsets + ( | |
651 | (None, { | |
652 | 'fields': ('nom', 'type_paiement', 'nature_remuneration', ) | |
653 | }), | |
654 | ) | |
6e7c919b | 655 | |
6e7c919b | 656 | |
3f486b41 OL |
657 | class TypeRevalorisationAdmin(AUFMetadataAdminMixin, admin.ModelAdmin): |
658 | #inlines = (RemunerationROInline,) utilité? | |
659 | fieldsets = AUFMetadataAdminMixin.fieldsets + ( | |
660 | (None, { | |
661 | 'fields': ('nom', ) | |
662 | }), | |
663 | ) | |
6e7c919b | 664 | |
6e7c919b | 665 | |
84fc088b | 666 | class ValeurPointAdmin(AUFMetadataAdminMixin, admin.ModelAdmin): |
701f3bea | 667 | list_display = ('_devise_code', '_devise_nom', 'annee', 'valeur', ) |
84fc088b OL |
668 | fieldsets = AUFMetadataAdminMixin.fieldsets + ( |
669 | (None, { | |
670 | 'fields': ('valeur', 'devise', 'implantation', 'annee', ) | |
671 | }), | |
672 | ) | |
701f3bea OL |
673 | |
674 | def _devise_code(self, obj): | |
675 | return obj.devise.code | |
676 | _devise_code.short_description = "Code de la devise" | |
677 | ||
678 | def _devise_nom(self, obj): | |
679 | return obj.devise.nom | |
680 | _devise_nom.short_description = "Nom de la devise" | |
49c98347 PP |
681 | |
682 | ||
683 | def calc_remun(dossier): | |
684 | thisyear = datetime.date.today().year | |
685 | thisyearfilter = Q(date_debut__year=thisyear) | Q(date_fin__year=thisyear) | |
686 | ||
da6c523f | 687 | remunnow = dossier.rh_remunerations.filter(thisyearfilter) |
49c98347 PP |
688 | |
689 | remun_sum = 0 | |
690 | remun_sum_euro = 0 | |
691 | sums = defaultdict(int) | |
692 | sums_euro = defaultdict(int) | |
693 | for r in remunnow: | |
694 | nature = r.type.nature_remuneration | |
695 | sums[nature] += r.montant | |
696 | sums_euro[nature] += r.montant_euro() | |
697 | remun_sum += r.montant | |
698 | remun_sum_euro += r.montant_euro() | |
699 | ||
700 | remun = {} | |
701 | sums = dict(sums) | |
702 | for n, s in sums.iteritems(): | |
703 | remun[n] = [sums[n], sums_euro[n]] | |
704 | ||
705 | return remun, remun_sum, remun_sum_euro |