fix
[auf_rh_dae.git] / project / dae / views.py
index c087e47..7277d8b 100644 (file)
@@ -221,13 +221,15 @@ def poste(request, key=None):
             for comparaison in comparaisons:
                 comparaison.poste = poste
                 comparaison.save()
+            saved_cmps = [x.id for x in comparaisons]
+
+            for cmp_f in comparaisons_formset.forms:
+                comparaison = (cmp_f.instance, cmp_f)
 
-            for comparaison in zip(
-                comparaisons,
-                comparaisons_formset.forms):
                 cmp_dossier_id = comparaison[1].cleaned_data.get(
                     'cmp_poste', None)
-                if not cmp_dossier_id:
+                if (not cmp_dossier_id or
+                    comparaison[0].id not in saved_cmps):
                     continue
                 cmp_dossier_qs = rh.Dossier.objects.filter(id=cmp_dossier_id)
                 if not cmp_dossier_qs.count() > 0:
@@ -503,14 +505,15 @@ def embauche(request, key=None, dossier_id=None):
             for comparaison in comparaisons:
                 comparaison.dossier = dossier
                 comparaison.save()
+            saved_cmps = [x.id for x in comparaisons]
 
-            for comparaison in zip(
-                comparaisons,
-                comparaisons_formset.forms):
+            for cmp_f in comparaisons_formset.forms:
+                comparaison = (cmp_f.instance, cmp_f)
 
                 cmp_dossier_id = comparaison[1].cleaned_data.get(
                     'cmp_dossier', None)
-                if not cmp_dossier_id:
+                if (not cmp_dossier_id or
+                    comparaison[0].id not in saved_cmps):
                     continue
                 cmp_dossier_qs = rh.Dossier.objects.filter(id=cmp_dossier_id)
                 if not cmp_dossier_qs.count() > 0:
@@ -592,6 +595,13 @@ def embauche(request, key=None, dossier_id=None):
     for cmp_form in comparaisons_formset.forms:
         cmp_form.fields['implantation'].queryset = imp_qs
 
+    # Comment out for now.
+    # if dossier and dossier.poste:
+    #     dossier_form.fields['employe_anterieur'].queryset = (
+    #         dossier_form.fields['employe_anterieur'].queryset.filter(
+    #             rh_dossiers__poste=dossier.poste,
+    #             ).distinct()
+    #         )
 
     c = {
         'type_remun': filtered_type_remun(),