Added archivable in list of classement
[auf_rh_dae.git] / project / rh / forms.py
CommitLineData
84cbb4c5
OL
1# -*- encoding: utf-8 -*-
2
fc62be5d
EMS
3from datetime import date
4
105dd778 5from ajax_select.fields import AutoCompleteSelectField
fc62be5d
EMS
6from auf.django.references import models as ref
7from django import forms
8from django.db.models import Min
9
f1d5cb6c 10from project.groups import get_employe_from_user, is_user_dans_region
fc62be5d 11from project.rh import models as rh
105dd778
OL
12
13
49c2f4ad
BS
14class ClassementHistoriqueForm(forms.ModelForm):
15 def __init__(self, *a, **kw):
16 super(ClassementHistoriqueForm, self).__init__(*a, **kw)
17 self.fields['classement'].queryset = rh.Classement.avec_archives.all()
18
19 class Meta:
20 model = rh.RHDossierClassementRecord
21
22
105dd778
OL
23class AjaxSelect(object):
24
25 class Media:
26 css = {
00119a5d
EMS
27 'all': (
28 'jquery-autocomplete/jquery.autocomplete.css',
29 'css/select.css',
30 )
105dd778 31 }
00119a5d
EMS
32 js = (
33 'js/jquery-1.5.1.min.js',
34 'jquery-autocomplete/jquery.autocomplete.js',
35 )
84cbb4c5
OL
36
37
38class FormDate(object):
39
40 def clean_date_fin(self):
41 date_fin = self.cleaned_data['date_fin']
42 if date_fin is None:
00119a5d 43 return date_fin
84cbb4c5
OL
44 date_debut = self.cleaned_data['date_debut']
45 if date_fin < date_debut:
00119a5d
EMS
46 raise forms.ValidationError(
47 u"La date de fin est antérieure à la date de début"
48 )
84cbb4c5
OL
49 return date_fin
50
00119a5d 51
105dd778 52class DossierForm(forms.ModelForm, FormDate):
00119a5d 53
84cbb4c5 54 class Model:
fc62be5d 55 model = rh.Dossier
84cbb4c5 56
6bee05ff 57
84cbb4c5
OL
58class ContratForm(forms.ModelForm, FormDate):
59
60 class Model:
fc62be5d 61 model = rh.Contrat
cf022e27 62
00119a5d 63
105dd778
OL
64class AyantDroitForm(forms.ModelForm, AjaxSelect):
65
ed4fbe26 66 # ne fonctionne pas dans un inline
cf022e27
OL
67
68 def __init__(self, *args, **kwargs):
69 super(AyantDroitForm, self).__init__(*args, **kwargs)
70 self.fields['date_naissance'].widget = forms.widgets.DateInput()
71
72 class Meta:
fc62be5d 73 model = rh.AyantDroit
cf022e27
OL
74
75
105dd778 76class EmployeAdminForm(forms.ModelForm, AjaxSelect):
00119a5d
EMS
77 nationalite = AutoCompleteSelectField(
78 'pays', help_text="Taper le nom ou le code du pays", required=False
79 )
80 pays = AutoCompleteSelectField(
81 'pays', help_text="Taper le nom ou le code du pays", required=False
82 )
105dd778
OL
83
84 class Meta:
fc62be5d 85 model = rh.Employe
105dd778
OL
86
87 def __init__(self, *args, **kwargs):
88 super(EmployeAdminForm, self).__init__(*args, **kwargs)
89 self.fields['date_naissance'].widget = forms.widgets.DateInput()
90
91
6fb68b2f 92class ResponsableInlineForm(forms.ModelForm):
6b4200cd 93 employes_actifs = rh.Employe.objects.actifs().distinct()
6fb68b2f
DB
94 employe = forms.ModelChoiceField(queryset=employes_actifs)
95
96 class Meta:
fc62be5d
EMS
97 model = rh.ResponsableImplantation
98
99
100class MasseSalarialeForm(forms.Form):
b0cf30b8
EMS
101 zone_administrative = forms.ModelChoiceField(
102 label=u'Région', queryset=ref.ZoneAdministrative.objects.all(),
103 required=False
fc62be5d
EMS
104 )
105 implantation = forms.ModelChoiceField(
106 label=u'Implantation', queryset=ref.Implantation.objects.all(),
107 required=False
108 )
109
110 def __init__(self, user, *args, **kwargs):
111 super(MasseSalarialeForm, self).__init__(*args, **kwargs)
112 min_date = rh.Remuneration.objects \
113 .aggregate(Min('date_debut'))['date_debut__min']
114 years = range(
115 date.today().year,
116 min_date.year if min_date else 1997,
117 -1
118 )
119 self.fields['annee'] = forms.TypedChoiceField(
120 label='Année', choices=zip(years, years), coerce=int,
121 required=False
122 )
f1d5cb6c 123 if is_user_dans_region(user):
fc62be5d 124 employe = get_employe_from_user(user)
b0cf30b8
EMS
125 self.fields['zone_administrative'].queryset = \
126 ref.ZoneAdministrative.objects.filter(
127 code=employe.implantation.zone_administrative.code
128 )
fc62be5d
EMS
129 self.fields['implantation'].queryset = \
130 ref.Implantation.objects.filter(
b0cf30b8
EMS
131 zone_administrative=(
132 employe.implantation.zone_administrative
133 )
fc62be5d 134 )