[#3165] Remplacé les filtres et protection par région pour des filtres et protections...
[auf_rh_dae.git] / project / rh / views.py
index 59b7e4b..5010814 100644 (file)
@@ -110,7 +110,11 @@ def rapports_contrat(request):
        groups.ADMINISTRATEURS in user_groups or\
        groups.DIRECTEUR_DE_BUREAU in user_groups:
         employe = get_employe_from_user(request.user)
-        q = q & Q(dossier__poste__implantation__region=employe.implantation.region)
+        q = q & Q(
+            dossier__poste__implantation__zone_administrative=(
+                employe.implantation.zone_administrative
+            )
+        )
 
     contrats = contrats.filter(q)
 
@@ -130,7 +134,7 @@ def rapports_contrat(request):
         ("date_debut", u"Début contrat"),
         ("date_fin", u"Fin contrat"),
         ("dossier__statut_residence", u"Statut"),
-        ("dossier__poste__implantation__region", u"Région"),
+        ("dossier__poste__implantation__zone_administrative", u"Zone administrative"),
         ("dossier__poste__implantation", u"Implantation"),
     ]
     h = SortHeaders(
@@ -168,7 +172,8 @@ def rapports_employes_sans_contrat(request):
        groups.ADMINISTRATEURS in user_groups or\
        groups.DIRECTEUR_DE_BUREAU in user_groups:
         employe = get_employe_from_user(request.user)
-        lookup_params['poste__implantation__region'] = employe.implantation.region
+        lookup_params['poste__implantation__zone_administrative'] = \
+                employe.implantation.zone_administrative
 
     
     dossiers = rh.Dossier.objects.sans_contrats_ou_echus(**lookup_params)
@@ -190,7 +195,7 @@ def rapports_employes_sans_contrat(request):
         ("rh_contrats__date_debut", u"Début contrat"),
         ("rh_contrats__date_fin", u"Fin contrat"),
         ("statut_residence", u"Statut"),
-        ("poste__implantation__region__code", u"Région"),
+        ("poste__implantation__zone_administrative__code", u"Zone administrative"),
         ("poste__implantation__nom", u"Implantation"),
     ]
     h = SortHeaders(
@@ -217,7 +222,7 @@ def rapports_employes_sans_contrat(request):
 def rapports_masse_salariale(request):
     form = MasseSalarialeForm(request.user, request.GET)
     if 'annee' in request.GET and form.is_valid():
-        region = form.cleaned_data['region']
+        zone_administrative = form.cleaned_data['zone_administrative']
         implantation = form.cleaned_data['implantation']
         annee = form.cleaned_data['annee']
         debut_annee = date(annee, 1, 1)
@@ -230,7 +235,7 @@ def rapports_masse_salariale(request):
                 .actifs(annee=annee) \
                 .select_related(
                     'poste', 'poste__implantation',
-                    'poste__implantation__region',
+                    'poste__implantation__zone_administrative',
                     'poste__implantation__adresse_physique_pays',
                     'employe', 'poste__type_poste', 'classement',
                     'statut', 'organisme_bstg'
@@ -251,8 +256,8 @@ def rapports_masse_salariale(request):
                         )
                     }
                 )
-        if region:
-            dossiers = dossiers.filter(poste__implantation__region=region)
+        if zone_administrative:
+            dossiers = dossiers.filter(poste__implantation__zone_administrative=zone_administrative)
         if implantation:
             dossiers = dossiers.filter(poste__implantation=implantation)
 
@@ -271,8 +276,8 @@ def rapports_masse_salariale(request):
                         'taux_change': 'rh_tauxchange.taux'
                     }
                 )
-        if region:
-            remuns = remuns.filter(dossier__poste__implantation__region=region)
+        if zone_administrative:
+            remuns = remuns.filter(dossier__poste__implantation__zone_administrative=zone_administrative)
         if implantation:
             remuns = remuns.filter(dossier__poste__implantation=implantation)
         remuns_par_dossier = defaultdict(list)
@@ -419,8 +424,8 @@ def rapports_masse_salariale(request):
                         'taux_change': 'rh_tauxchange.taux'
                     }
                 )
-        if region:
-            postes = postes.filter(implantation__region=region)
+        if zone_administrative:
+            postes = postes.filter(implantation__zone_administrative=zone_administrative)
         if implantation:
             postes = postes.filter(implantation=implantation)
         postes = list(postes)
@@ -666,8 +671,12 @@ def employe_apercu(request, employe_id):
        groups.ADMINISTRATEURS in user_groups or\
        groups.DIRECTEUR_DE_BUREAU in user_groups:
         employe_connecte = get_employe_from_user(request.user)
-        q = Q(employe=employe) & Q(poste__implantation__region=employe_connecte.implantation.region)
-    
+        q = Q(employe=employe) & Q(
+            poste__implantation__zone_administrative=(
+                employe_connecte.implantation.zone_administrative
+            )
+        )
+
     dossiers = rh.Dossier.objects.filter(q).order_by('-date_debut')
 
     c = {