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