From 7777eb1b32530d1514f44a7c14f1937545a24a26 Mon Sep 17 00:00:00 2001
From: benjamin <benjamin@le-filament.com>
Date: Thu, 5 Dec 2024 15:57:15 +0100
Subject: [PATCH] [UPD] get_liasse function

---
 models/scop_cotisation_cg.py | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/models/scop_cotisation_cg.py b/models/scop_cotisation_cg.py
index 87e5a2f..dc02f46 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:
-- 
GitLab