Fix
[auf_rh_dae.git] / project / dae / views.py
index c087e47..f9711d0 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: