From 1182e545659203cff26e87b265f41b64ecf18a59 Mon Sep 17 00:00:00 2001
From: "CGSCOP\\hsilvant" <hsilvant@scop.coop>
Date: Tue, 1 Apr 2025 16:46:35 +0200
Subject: [PATCH] =?UTF-8?q?Ajout=20des=20cotisations=20PACA=20dans=20la=20?=
 =?UTF-8?q?vue=20synth=C3=A9tique=20des=20cotisations?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 __manifest__.py                    |  1 +
 report/scop_contribution_report.py | 57 ++++++++++++++++++++++++++++++
 2 files changed, 58 insertions(+)

diff --git a/__manifest__.py b/__manifest__.py
index 5828f6d..c548bac 100644
--- a/__manifest__.py
+++ b/__manifest__.py
@@ -16,6 +16,7 @@
         "cgscop_account",
         "cgscop_liasse_fiscale",
         "cgscop_partner",
+        "cgscop_cotisation_paca",
         "lefilament_sales",
     ],
     "data": [
diff --git a/report/scop_contribution_report.py b/report/scop_contribution_report.py
index 2240a52..f70132d 100644
--- a/report/scop_contribution_report.py
+++ b/report/scop_contribution_report.py
@@ -50,6 +50,61 @@ class ScopContributionReport(models.Model):
         ],
     }
 
+    # ------------------------------------------------------
+    # Sub Query PACA
+    # ------------------------------------------------------
+    def _select_paca(self):
+
+        type_coti_ur = self.env.ref("cgscop_partner.riga_14399").id
+
+        select_str = """
+            SELECT
+                'odoo' as source,
+                CAST(i.annee AS VARCHAR),
+                %d AS type_contribution_id,
+                i.partner_id,
+                SUM(i.mt_coti) AS amount_called,
+                SUM(i.mt_paid) AS amount_paid,
+                SUM(i.mt_coti - i.mt_paid) AS amount_due
+        """ % (
+            type_coti_ur,
+        )
+        return select_str
+
+    def _from_paca(self):
+        from_str = """
+                    FROM
+                        scop_cotisation_paca i
+                """
+        return from_str
+
+    def _where_paca(self):
+        where_str = """
+            WHERE
+                i.partner_id IS NOT NULL
+        """
+        return where_str
+
+    def _groupby_paca(self):
+        groupby_str = """
+            GROUP BY
+                i.annee,
+                i.partner_id
+        """
+        return groupby_str
+
+    def _query_paca(self):
+        query = "(%s %s %s %s)" % (
+            self._select_paca(),
+            self._from_paca(),
+            self._where_paca(),
+            self._groupby_paca(),
+        )
+        return query
+
+    def _subquerypaca(self):
+        return self._query_paca()
+
     # ------------------------------------------------------
     # Sub Query
     # ------------------------------------------------------
@@ -137,6 +192,8 @@ class ScopContributionReport(models.Model):
         query = (
             self._select()
             + self._subquery()
+            +" UNION ALL "
+            + self._subquerypaca()
             + ") c "
             + self._query_groupby()
             + self._query_order()
-- 
GitLab