Merge branch 'release/1.8'
authorBenoit C. Sirois <benoit.clennett-sirois@auf.org>
Tue, 7 May 2013 14:10:10 +0000 (10:10 -0400)
committerBenoit C. Sirois <benoit.clennett-sirois@auf.org>
Tue, 7 May 2013 14:10:10 +0000 (10:10 -0400)
project/rh/models.py

index fc857d4..981a495 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
@@ -1211,7 +1212,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