From 9b54980b31d33e1c45d0207a632cc38941561d5a Mon Sep 17 00:00:00 2001
From: Emmanuel Viennet <emmanuel.viennet@gmail.com>
Date: Wed, 7 Sep 2022 13:07:11 +0200
Subject: [PATCH] =?UTF-8?q?Fix:=20modification=20d=C3=A9cisions=20UE=20jur?=
 =?UTF-8?q?y=20BUT?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 app/but/jury_but.py | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/app/but/jury_but.py b/app/but/jury_but.py
index c4236910c..0d7ca77c6 100644
--- a/app/but/jury_but.py
+++ b/app/but/jury_but.py
@@ -895,12 +895,11 @@ class DecisionsProposeesUE(DecisionsProposees):
         self.validation = ScolarFormSemestreValidation.query.filter_by(
             etudid=etud.id, formsemestre_id=formsemestre.id, ue_id=ue.id
         ).first()
-
         super().__init__(
             etud=etud,
             code_valide=self.validation.code if self.validation is not None else None,
         )
-
+        log(f"built {self}")
         self.formsemestre = formsemestre
         self.ue: UniteEns = ue
         self.rcue: RegroupementCoherentUE = None
@@ -951,7 +950,9 @@ class DecisionsProposeesUE(DecisionsProposees):
             self.explanation = "notes insuffisantes"
 
     def record(self, code: str, no_overwrite=False):
-        """Enregistre le code"""
+        """Enregistre le code jury pour cette UE.
+        Si no_overwrite, n'enregistre pas s'il y a déjà un code.
+        """
         if code and not code in self.codes:
             raise ScoValueError(
                 f"code UE invalide pour ue_id={self.ue.id}: {html.escape(code)}"
@@ -959,9 +960,7 @@ class DecisionsProposeesUE(DecisionsProposees):
         if code == self.code_valide or (self.code_valide is not None and no_overwrite):
             self.recorded = True
             return  # no change
-        if self.validation:
-            db.session.delete(self.validation)
-            db.session.flush()
+        self.erase()
         if code is None:
             self.validation = None
         else:
@@ -977,6 +976,7 @@ class DecisionsProposeesUE(DecisionsProposees):
                 etudid=self.etud.id,
                 msg=f"Validation UE {self.ue.id}",
             )
+            log(f"DecisionsProposeesUE: recording {self.validation}")
             db.session.add(self.validation)
 
         sco_cache.invalidate_formsemestre(formsemestre_id=self.formsemestre.id)
@@ -989,6 +989,7 @@ class DecisionsProposeesUE(DecisionsProposees):
             etudid=self.etud.id, formsemestre_id=self.formsemestre.id, ue_id=self.ue.id
         )
         for validation in validations:
+            log(f"DecisionsProposeesUE: deleting {validation}")
             db.session.delete(validation)
         db.session.flush()