Rapport employés sans contrats
[auf_rh_dae.git] / project / rh / views.py
index 4c9d4da..31a7dc4 100644 (file)
@@ -289,6 +289,52 @@ def rapports_remuneration(request):
 
 @login_required
 @drh_or_admin_required
+def rapports_employe_sans_contrat(request):
+
+    lookup_params = dict(request.GET.items())
+    if 'ot' in lookup_params:
+        del lookup_params['ot']
+    if 'o' in lookup_params:
+        del lookup_params['o']
+
+    for key, value in lookup_params.items():
+        if not isinstance(key, str):
+            # 'key' will be used as a keyword argument later, so Python
+            # requires it to be a string.
+            del lookup_params[key]
+            lookup_params[smart_str(key)] = value
+
+    employes_query = rh.Employe.objects
+    if 'o' in request.GET:
+        employes_query = employes_query.order_by("%s%s" % ('-' if 'ot' in request.GET and request.GET['ot'] == "desc" else '', request.GET['o']))
+
+    employes = []
+    for e in employes_query.all():
+        dossiers = e.rh_dossiers.filter(Q(date_fin=None) | Q(date_fin__gt=date.today())).all()
+        for d in dossiers:
+            contrats = rh.Contrat.objects.filter(Q(dossier=d) & Q(date_fin__lt=date.today())).all()
+            if contrats:
+                employes.append({'employe': e, 'dossiers': dossiers})
+
+    headers = [
+        ("dossier__employe__id", u"# de l'employé"),
+        ("dossier__employe__nom", u"Nom"),
+        ("dossier__employe__prenom", u"Prénom"),
+        ("", u"Dossiers"),
+    ]
+    h = SortHeaders(request, headers, order_field_type="ot", order_field="o")
+
+    c = {
+        'title': u'Rapport des employés sans contrat',
+        'employes': employes,
+        'count': len(employes),
+        'headers': list(h.headers()),
+    }
+
+    return render_to_response('rh/rapports/employes_sans_contrat.html', c, RequestContext(request))
+
+@login_required
+@drh_or_admin_required
 def rapports_postes_modelisation(request):
     c = {}
     data = []