Fix for odette bug_multiple_objects
authorBenoit C. Sirois <benoit.clennett-sirois@auf.org>
Wed, 1 May 2013 20:58:56 +0000 (16:58 -0400)
committerBenoit C. Sirois <benoit.clennett-sirois@auf.org>
Wed, 1 May 2013 20:58:56 +0000 (16:58 -0400)
project/rh/models.py

index 9b2af7a..5a6170d 100644 (file)
@@ -10,6 +10,7 @@ from auf.django.emploi.models import \
 from auf.django.references import models as ref
 from django.contrib.auth.models import User
 from django.core.files.storage import FileSystemStorage
+from django.core.exceptions import MultipleObjectsReturned
 from django.db import models
 from django.db.models import Q
 from django.db.models.signals import post_save, pre_save
@@ -1193,7 +1194,16 @@ class RHDossierClassementRecord(models.Model):
                     dossier=instance,
                     )
                 previous_classement = instance.before_save.classement
-
+        except MultipleObjectsReturned:
+            qs = cls.objects.filter(
+                dossier=instance,
+                classement=instance.before_save.classement,
+                date_fin=None,
+                )
+            latest = qs.latest('date_debut')
+            qs.exclude(id=latest.id).update(date_fin=today)
+            previous_record = latest
+            previous_classement = latest.classement
         else:
             previous_classement = previous_record.classement