From 8bebdfb34ad7c6432b8888cc4f7a2da979b977f1 Mon Sep 17 00:00:00 2001 From: benjamin <benjamin@le-filament.com> Date: Thu, 24 Apr 2025 10:47:10 +0200 Subject: [PATCH] [ADD] contribution in contribution report --- __init__.py | 2 +- __manifest__.py | 1 + report/__init__.py | 1 + report/scop_contribution_report.py | 88 ++++++++++++++++++++++++++++++ 4 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 report/__init__.py create mode 100644 report/scop_contribution_report.py diff --git a/__init__.py b/__init__.py index 48e1758..08831fc 100644 --- a/__init__.py +++ b/__init__.py @@ -2,4 +2,4 @@ # © 2020 Confédération Générale des Scop (<https://www.les-scop.coop>) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from . import models +from . import models, report diff --git a/__manifest__.py b/__manifest__.py index 6d85925..e5dd73d 100644 --- a/__manifest__.py +++ b/__manifest__.py @@ -8,6 +8,7 @@ "license": "AGPL-3", "depends": [ "cgscop_partner", + "cgscop_cotisation", ], "data": [ # security diff --git a/report/__init__.py b/report/__init__.py new file mode 100644 index 0000000..e6800d8 --- /dev/null +++ b/report/__init__.py @@ -0,0 +1 @@ +from . import scop_contribution_report diff --git a/report/scop_contribution_report.py b/report/scop_contribution_report.py new file mode 100644 index 0000000..5b5c2c6 --- /dev/null +++ b/report/scop_contribution_report.py @@ -0,0 +1,88 @@ +# © 2022 Le Filament (<http://www.le-filament.com>) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +import logging + +from psycopg2.extensions import AsIs + +from odoo import api, fields, models, tools + +_logger = logging.getLogger(__name__) + + +class ScopContributionReport(models.Model): + _inherit = "scop.contribution.report" + + # ------------------------------------------------------ + # 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.year AS VARCHAR), + %d AS type_contribution_id, + i.partner_id, + SUM(i.amount_contribution) AS amount_called, + SUM(i.amount_paid) AS amount_paid, + SUM(i.amount_contribution - i.amount_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.year, + 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 + # ------------------------------------------------------ + def _subquery(self): + sub_query = super(ScopContributionReport, self)._subquery() + return f"{sub_query} UNION ALL {self._subquerypaca()}" + + # ------------------------------------------------------ + # Main Query + # ------------------------------------------------------ + + # ------------------------------------------------------ + # Computed fields + # ------------------------------------------------------ + + # ------------------------------------------------------ + # Business functions + # ------------------------------------------------------ -- GitLab