diff --git a/models/scop_cotisation_cg.py b/models/scop_cotisation_cg.py index 87e5a2f666b051d9a79e21d89472ab2dec20d370..dc02f468680d708584f5136d51a2360df1f7e9e5 100644 --- a/models/scop_cotisation_cg.py +++ b/models/scop_cotisation_cg.py @@ -889,15 +889,19 @@ class ScopCotisation(models.Model): [("partner_id", "=", member.id), ("year", "=", str(int(self.year) - 1))] ) liasse_ids = None - if bdx: + if ( + bdx + and bdx.liasse_fiscale_id + and bdx.liasse_fiscale_id.year == int(self.year) - 3 + ): # Recherche liasse année suivante liasse_ids = Liasse.search( [ ("partner_id", "=", member.id), ("is_qualified", "=", True), - ("year", "=", bdx.liasse_fiscale_id.year + 1), + ("year", "=", int(self.year) - 2), ], - order="type_id", + order="type_id,id desc", ) # Si pas de liasse année suivante, on cherche la dernière liasse éligible if not liasse_ids: @@ -912,7 +916,7 @@ class ScopCotisation(models.Model): ("av_lf", "!=", 0), ("av_cg", "!=", 0), ], - order="year desc", + order="year desc,id desc", ) # Si pas de liasse cette année, on cherche les liasses sans année if not liasse_ids: