Skip to content
Extraits de code Groupes Projets
Sélectionner une révision Git
  • 67f4130523b83ab9db42397b572e7005ff976ed5
  • 16.0 par défaut protégée
2 résultats

acc_operation.py

Blame
  • Bifurcation depuis Le Filament / Opération Auto-Consommation Collective / oacc_portal
    Le projet source a une visibilité limitée.
    partner_dashboard_ur.py 33,29 Kio
    # © 2020 Le Filament (<https://www.le-filament.com>)
    # © 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).
    
    import datetime
    import json
    
    from psycopg2.extensions import AsIs
    
    from odoo import api, fields, models, tools
    
    
    class ScopPartnerDashboardUr(models.Model):
        _name = "scop.partner.dashboard.ur"
        _description = "Dashboard coopératives UR"
        _order = "dash_type asc"
        _auto = False
    
        current_user_ur_id = fields.Many2one(
            "union.regionale",
            string="Union Régionale de l'utilisateur",
            compute="_compute_current_user_ur_id",
            search="_search_current_user_ur_id",
        )
    
        # Vue
        ur_id = fields.Many2one("union.regionale", string="Union Régionale")
        name = fields.Char()
        dash_type = fields.Integer("Type de dashboard")
        all_ur = fields.Boolean("Affichage de toutes les UR")
    
        nb_prj_info = fields.Integer("Information")
        nb_prj_pdiag = fields.Integer("Pre-diag")
        nb_prj_accomp = fields.Integer("Accompagnement")
        nb_prj_adh = fields.Integer("Adhésion")
        nb_prj_soumis = fields.Integer("Soumis")
        nb_prj_tot = fields.Integer("Projets en cours")
    
        nb_fc_scop = fields.Integer("Nombre de scop")
        nb_fc_scic = fields.Integer("Nombre de scic")
        nb_fc_co47 = fields.Integer("Nombre de coop 47")
        nb_coop_cae = fields.Integer("Nombre de CAE")
        nb_coop_adh = fields.Integer("Nombre d'adhésion pour l'année")
        nb_coop_tot = fields.Integer("Total coop adhérentes")
    
        rev_todo = fields.Integer("A réviser")
        rev_done = fields.Integer("Révisées")
        rev_total = fields.Integer("Total révisions")
        rev_1y = fields.Integer("Annuelle")
        rev_5y = fields.Integer("Quinquennale")
        rev_5ys = fields.Integer("Quinquennale séquencée (annuel)")
        rev_5ys23 = fields.Integer("Quinquennale séquencée (2 ans et 3 ans)")
        rev_percent_done = fields.Float(
            "Réévisions Réalisées", compute="_compute_percent_rev"
        )
    
        act_dev = fields.Integer("Développement (hrs)")
        act_acc = fields.Integer("Suivi (hrs)")
        act_rev = fields.Integer("Révision (hrs)")
        act_for = fields.Integer("Formation (hrs)")
        act_acc_theo = fields.Integer("Acc. théorique (hrs)")
        act_acc_percent_done = fields.Float("Réalisés", compute="_compute_act_acc")
    
        graph_values = fields.Text(compute="_compute_graph_values")
    
        # ------------------------------------------------------
        # Construction de la requete
        # ------------------------------------------------------
        @api.model
        def _select(self):
            # On récupere l'id de la cgscop
            cgids = self.env["union.regionale"].search([("name", "ilike", "CGSCOP")])
            if not cgids:
                cgscop_id = 0
            else:
                cgscop_id = cgids[0].id
    
            # On constitue les requetes
            qy_projet = self._select_projet(cgscop_id)
            qy_coop = self._select_coop(cgscop_id)
            qy_rev = self._select_rev(cgscop_id)
            qy_act = self._select_act(cgscop_id)
    
            qy = """
                WITH req AS (%s UNION ALL %s UNION ALL %s UNION ALL %s)
                SELECT ROW_NUMBER() OVER (ORDER BY ur_id) as id, *
                FROM req
            """ % (
                qy_projet,
                qy_coop,
                qy_rev,
                qy_act,
            )
            return qy
    
        # ------------------------------------------------------
        # Dashboard projets
        # ------------------------------------------------------
        @api.model
        def _select_projet(self, cgscop_id):
            query = """
                    SELECT
                    CONCAT('1', ur_id) AS id_txt,
                    org.ur_id as ur_id,
                    'Prospects en cours' AS name,
                    1 as dash_type,
                    0 as all_ur,
                    SUM(case
                        when substring(org.project_status,1,1) = '1' then 1
                        else 0 end) AS nb_prj_info,
                    SUM(case
                        when substring(org.project_status,1,1) = '2' then 1
                        else 0 end) AS nb_prj_pdiag,
                    SUM(case
                        when substring(org.project_status,1,1) = '3' then 1
                        else 0 end) AS nb_prj_accomp,
                    SUM(case
                        when substring(org.project_status,1,1) = '4' then 1
                        else 0 end) AS nb_prj_adh,
                    SUM(case when
                        substring(org.project_status,1,1) = '5' then 1
                        else 0 end) AS nb_prj_soumis,
                    count(org.id) as nb_prj_tot,
                    0 as nb_fc_scop,
                    0 as nb_fc_scic,
                    0 as nb_fc_co47,
                    0 as nb_coop_cae,
                    0 as nb_coop_adh,
                    0 as nb_coop_tot,
                    0 as rev_done,
                    0 as rev_1y,
                    0 as rev_5y,
                    0 as rev_5ys,
                    0 as rev_5ys23,
                    0 as rev_todo,
                    0 as rev_total,
                    0 as act_dev,
                    0 as act_acc,
                    0 as act_rev,
                    0 as act_for,
                    0 as act_acc_theo
                    FROM res_partner org
                    where
                    (org.ur_id <> %d) and
                    (org.active=TRUE) and
                    (org.is_cooperative = TRUE)and
                    substring(org.project_status,1,1) in ('1','2','3','4','5')
                    group by
                    org.ur_id
                    UNION ALL
                    SELECT
                    '1CGSCOP' AS id_txt,
                    '%d' as ur_id,
                    'Prospects en cours' AS name,
                    1 as dash_type,
                    1 as all_ur,
                    SUM(case
                        when substring(org.project_status,1,1) = '1' then 1
                        else 0 end) AS nb_prj_info,
                    SUM(case
                        when substring(org.project_status,1,1) = '2' then 1
                        else 0 end) AS nb_prj_pdiag,
                    SUM(case
                        when substring(org.project_status,1,1) = '3' then 1
                        else 0 end) AS nb_prj_accomp,
                    SUM(case
                        when substring(org.project_status,1,1) = '4' then 1
                        else 0 end) AS nb_prj_adh,
                    SUM(case
                        when substring(org.project_status,1,1) = '5' then 1
                        else 0 end) AS nb_prj_soumis,
                    count(org.id) as nb_prj_tot,
                    0 as nb_fc_scop,
                    0 as nb_fc_scic,
                    0 as nb_fc_co47,
                    0 as nb_coop_cae,
                    0 as nb_coop_adh,
                    0 as nb_coop_tot,
                    0 as rev_done,
                    0 as rev_1y,
                    0 as rev_5y,
                    0 as rev_5ys,
                    0 as rev_5ys23,
                    0 as rev_todo,
                    0 as rev_total,
                    0 as act_dev,
                    0 as act_acc,
                    0 as act_rev,
                    0 as act_for,
                    0 as act_acc_theo
                    FROM res_partner org
                    where
                    (org.active=TRUE) and
                    (org.is_cooperative = TRUE)and
                    substring(org.project_status,1,1) in ('1','2','3','4','5')
                    """ % (
                cgscop_id,
                cgscop_id,
            )
    
            return query
    
        # ------------------------------------------------------
        # Dashboard cooperative
        # ------------------------------------------------------
        @api.model
        def _select_coop(self, cgscop_id):
            try:
                form_scop = self.env.ref("cgscop_partner.form_scop").id
            except Exception:
                form_scop = 0
    
            try:
                form_scic = self.env.ref("cgscop_partner.form_scic").id
            except Exception:
                form_scic = 0
    
            try:
                form_co47 = self.env.ref("cgscop_partner.form_coop47").id
            except Exception:
                form_co47 = 0
    
            query = """
                    SELECT
                    CONCAT('2', ur_id) AS id_txt,
                    org.ur_id as ur_id,
                    'Coopératives adhérentes' AS name,
                    2 as dash_type,
                    0 as all_ur,
                    0 as nb_prj_info,
                    0 as nb_prj_pdiag,
                    0 as nb_prj_accomp,
                    0 as nb_prj_adh,
                    0 as nb_prj_soumis,
                    0 as nb_prj_tot,
                    SUM(case
                        when org.cooperative_form_id = %d then 1
                        else 0 end) AS nb_fc_scop,
                    SUM(case
                        when org.cooperative_form_id = %d then 1
                        else 0 end) AS nb_fc_scic,
                    SUM(case
                        when org.cooperative_form_id = %d then 1
                        else 0 end) AS nb_fc_co47,
                    SUM(case
                        when org.cae is true then 1
                        else 0 end) AS nb_coop_cae,
                    SUM(case
                        when date_part('year', adh.start) = date_part('year', CURRENT_DATE) then 1
                        else 0 end) AS nb_coop_adh,
                    count(org.id) as nb_coop_tot,
                    0 as rev_done,
                    0 as rev_1y,
                    0 as rev_5y,
                    0 as rev_5ys,
                    0 as rev_5ys23,
                    0 as rev_todo,
                    0 as rev_total,
                    0 as act_dev,
                    0 as act_acc,
                    0 as act_rev,
                    0 as act_for,
                    0 as act_acc_theo
                    FROM res_partner org
                    left join scop_membership_period as adh
                    on adh.partner_id = org.id
                    and adh.start=(select max(start)
                    from scop_membership_period where partner_id=org.id and type_id=1)
                    and type_id=1
                    where
                    (org.ur_id <> %d) and
                    (org.active=TRUE) and
                    (org.is_cooperative = TRUE) and
                    (org.membership_status = 'member')
                    group by
                    org.ur_id
                    UNION ALL
                    SELECT
                    '2CGSCOP' AS id_txt,
                    '%d' as ur_id,
                    'Coopératives adhérentes' AS name,
                    2 as dash_type,
                    1 as all_ur,
                    0 as nb_prj_info,
                    0 as nb_prj_pdiag,
                    0 as nb_prj_accomp,
                    0 as nb_prj_adh,
                    0 as nb_prj_soumis,
                    0 as nb_prj_tot,
                    SUM(case
                        when org.cooperative_form_id = %d then 1
                        else 0 end) AS nb_fc_scop,
                    SUM(case
                        when org.cooperative_form_id = %d then 1
                        else 0 end) AS nb_fc_scic,
                    SUM(case
                        when org.cooperative_form_id = %d then 1
                        else 0 end) AS nb_fc_co47,
                    SUM(case
                        when org.cae is true then 1
                        else 0 end) AS nb_coop_cae,
                    SUM(case
                        when date_part('year', adh.start) = date_part('year', CURRENT_DATE) then 1
                        else 0 end) AS nb_coop_adh,
                    count(org.id) as nb_coop_tot,
                    0 as rev_done,
                    0 as rev_1y,
                    0 as rev_5y,
                    0 as rev_5ys,
                    0 as rev_5ys23,
                    0 as rev_todo,
                    0 as rev_total,
                    0 as act_dev,
                    0 as act_acc,
                    0 as act_rev,
                    0 as act_for,
                    0 as act_acc_theo
                    FROM res_partner org
                    left join scop_membership_period as adh
                    on adh.partner_id = org.id
                    and adh.start=(select max(start)
                    from scop_membership_period where partner_id=org.id and type_id=1)
                    and type_id=1
                    where
                    (org.active=TRUE) and
                    (org.is_cooperative = TRUE) and
                    (org.membership_status = 'member')
                    """ % (
                form_scop,
                form_scic,
                form_co47,
                cgscop_id,
                cgscop_id,
                form_scop,
                form_scic,
                form_co47,
            )
    
            return query
    
        # ------------------------------------------------------
        # Dashboard revision
        # ------------------------------------------------------
        @api.model
        def _select_rev(self, cgscop_id):
            query = """
                    SELECT
                    id_txt,
                    ur_id,
                    CONCAT('Révisions année ',date_part('year', CURRENT_DATE)) AS name,
                    3 as dash_type,
                    0 as all_ur,
                    0 as nb_prj_info,
                    0 as nb_prj_pdiag,
                    0 as nb_prj_accomp,
                    0 as nb_prj_adh,
                    0 as nb_prj_soumis,
                    0 as nb_prj_tot,
                    0 as nb_fc_scop,
                    0 as nb_fc_scic,
                    0 as nb_fc_co47,
                    0 as nb_coop_cae,
                    0 as nb_coop_adh,
                    0 as nb_coop_tot,
                    SUM(wrev.rev_done) as rev_done,
                    SUM(wrev.rev_1y) AS rev_1y,
                    SUM(wrev.rev_5y) AS rev_5y,
                    SUM(wRev.rev_5ys) AS rev_5ys,
                    SUM(wrev.rev_5ys23) AS rev_5ys23,
                    SUM(wrev.rev_1y) + SUM(wrev.rev_5y) + SUM(wRev.rev_5ys) +
                    SUM(wrev.rev_5ys23) AS rev_todo,
                    SUM(wrev.rev_done) + SUM(wrev.rev_1y) + SUM(wrev.rev_5y) +
                    SUM(wRev.rev_5ys) + SUM(wrev.rev_5ys23) AS rev_total,
                    0 as act_dev,
                    0 as act_acc,
                    0 as act_rev,
                    0 as act_for,
                    0 as act_acc_theo
                    FROM
                    (
                        SELECT
                        CONCAT(org.ur_id, org.revision_next_year) AS id_txt,
                        org.ur_id as ur_id,
                        0 AS rev_done,
                        case when org.revision_type = '1y' then 1 else 0 end AS rev_1y,
                        case when org.revision_type = '5y' then 1 else 0 end AS rev_5y,
                        case when org.revision_type = '5ys' then 1 else 0 end AS rev_5ys,
                        case when org.revision_type = '5ys23' then 1 else 0 end AS rev_5ys23
                        FROM res_partner as org
                        WHERE (org.revision_next_year = date_part('year', CURRENT_DATE))
                    UNION ALL
                        SELECT
                        CONCAT(org.ur_id, date_part('year', rev.date)) as id_txt,
                        org.ur_id as ur_id,
                        1 AS rev_done,
                        0 AS rev_1y,
                        0 AS rev_5y,
                        0 AS rev_5ys,
                        0 AS rev_5ys23
                        FROM scop_revision as rev
                        JOIN res_partner as org ON (org.id = rev.partner_id)
                        WHERE (date_part('year', rev.date) = date_part('year', CURRENT_DATE))
                    ) AS wRev
                    GROUP BY wrev.id_txt, wrev.ur_id
            """
            return query
    
        # ------------------------------------------------------
        # Dashboard activité
        # ------------------------------------------------------
        @api.model
        def _select_act(self, cgscop_id):
            query = """
                    SELECT
                    CONCAT('4', ur_id) as id_txt,
                    ur_id,
                    CONCAT('Activité année ',date_part('year', CURRENT_DATE)) AS name,
                    4 as dash_type,
                    0 as all_ur,
                    0 as nb_prj_info,
                    0 as nb_prj_pdiag,
                    0 as nb_prj_accomp,
                    0 as nb_prj_adh,
                    0 as nb_prj_soumis,
                    0 as nb_prj_tot,
                    0 as nb_fc_scop,
                    0 as nb_fc_scic,
                    0 as nb_fc_co47,
                    0 as nb_coop_cae,
                    0 as nb_coop_adh,
                    0 as nb_coop_tot,
                    0 as rev_done,
                    0 as rev_1y,
                    0 AS rev_5y,
                    0 AS rev_5ys,
                    0 AS rev_5ys23,
                    0 AS rev_todo,
                    0 AS rev_total,
                    sum(wrk.amount_dev) as act_dev,
                    sum(wrk.amount_acc) as act_acc,
                    sum(wrk.amount_rev) as act_rev,
                    sum(wrk.amount_for) as act_for,
                    sum(wrk.amount_theo) as act_acc_theo
                    FROM
                    (
                        select
                        ac.ur_id as ur_id,
                        EXTRACT(YEAR FROM ac.date) as "year",
                        ac.unit_amount as amount_rev,
                        0 as amount_dev,
                        0 as amount_acc,
                        0 as amount_for,
                        0 as amount_theo
                        from
                        account_analytic_line as ac
                        left join project_project as pu on pu.id = ac.project_id
                        left join cgscop_timesheet_code as pn on pn.id = pu.cgscop_timesheet_code_id
                        where
                        (date_part('year', ac.date) = date_part('year', CURRENT_DATE))
                        and pn.domain = 'R'
                    union all
                        select
                        ac.ur_id as ur_id,
                        EXTRACT(YEAR FROM ac.date) as "year",
                        0 as amount_rev,
                        ac.unit_amount as amount_dev,
                        0 as amount_acc,
                        0 as amount_for,
                        0 as amount_theo
                        from
                        account_analytic_line as ac
                        left join project_project as pu on pu.id = ac.project_id
                        left join cgscop_timesheet_code as pn on pn.id = pu.cgscop_timesheet_code_id
                        where
                        (date_part('year', ac.date) = date_part('year', CURRENT_DATE))
                        and pn.domain = 'D'
                    union all
                        select
                        ac.ur_id as ur_id,
                        EXTRACT(YEAR FROM ac.date) as "year",
                        0 as amount_rev,
                        0 as amount_dev,
                        ac.unit_amount as amount_acc,
                        0 as amount_for,
                        0 as amount_theo
                        from
                        account_analytic_line as ac
                        left join project_project as pu on pu.id = ac.project_id
                        left join cgscop_timesheet_code as pn on pn.id = pu.cgscop_timesheet_code_id
                        where
                        (date_part('year', ac.date) = date_part('year', CURRENT_DATE))
                        and pn.domain = 'A'
                    union all
                        select
                        ac.ur_id as ur_id,
                        EXTRACT(YEAR FROM ac.date) as "year",
                        0 as amount_rev,
                        0 as amount_dev,
                        0 as amount_acc,
                        ac.unit_amount as amount_for,
                        0 as amount_theo
                        from
                        account_analytic_line as ac
                        left join project_project as pu on pu.id = ac.project_id
                        left join cgscop_timesheet_code as pn on pn.id = pu.cgscop_timesheet_code_id
                        where
                        (date_part('year', ac.date) = date_part('year', CURRENT_DATE))
                        and pn.domain = 'F'
                    union all
                        select
                        pa.ur_id as ur_id,
                        date_part('year', CURRENT_DATE) as "year",
                        0 as amount_rev,
                        0 as amount_dev,
                        0 as amount_acc,
                        0 as amount_for,
                        fo.duree as act_acc_theo
                        from
                        res_partner as pa
                        left join scop_followup_format as fo on fo.id = pa.followup_format_id
                        where pa.membership_status = 'member'
                    ) as wrk
                    group BY
                    wrk.ur_id,
                    wrk.year
            """
            return query
    
        def init(self):
            tools.drop_view_if_exists(self.env.cr, self._table)
            self.env.cr.execute(
                "CREATE or REPLACE VIEW %s as (%s)",
                (AsIs(self._table), AsIs(self._select())),
            )
    
        # ------------------------------------------------------
        # Récupère l'ur de l'utilisateur connecté
        # ------------------------------------------------------
        @api.model
        def _compute_current_user_ur_id(self):
            for partner in self:
                partner.current_user_ur_id = self.env.company.ur_id.id
    
        def _search_current_user_ur_id(self, operator, value):
            return [("ur_id", "=", self.env.company.ur_id.id)]
    
        # ------------------------------------------------------
        # Calcule les données du graphique
        # ------------------------------------------------------
        def _compute_graph_values(self):
            for rec in self:
                if rec.dash_type == 1:
                    rec.graph_values = json.dumps(
                        [
                            {
                                "values": [
                                    {
                                        "label": "Information",
                                        "value": rec.nb_prj_info,
                                    },
                                    {
                                        "label": "Pré-diag",
                                        "value": rec.nb_prj_pdiag,
                                    },
                                    {
                                        "label": "Accompagnement",
                                        "value": rec.nb_prj_accomp,
                                    },
                                    {"label": "Adhésion", "value": rec.nb_prj_adh},
                                    {
                                        "label": "Soumis CG",
                                        "value": rec.nb_prj_soumis,
                                    },
                                ],
                                "area": True,
                                "title": "",
                                "key": "Prospects en cours",
                            }
                        ]
                    )
    
                if rec.dash_type == 2:
                    rec.graph_values = json.dumps(
                        [
                            {
                                "values": [
                                    {"label": "Scop", "value": rec.nb_fc_scop},
                                    {"label": "Scic", "value": rec.nb_fc_scic},
                                    {"label": "Coop 47", "value": rec.nb_fc_co47},
                                ],
                                "area": True,
                                "title": "",
                                "key": "Coopératives adhérentes",
                            }
                        ]
                    )
    
                if rec.dash_type == 3:
                    rec.graph_values = json.dumps(
                        [
                            {
                                "values": [
                                    {"label": "Annuelle", "value": rec.rev_1y},
                                    {"label": "Quinquennale", "value": rec.rev_5y},
                                    {
                                        "label": "Quinq. séq. (annuel)",
                                        "value": rec.rev_5ys,
                                    },
                                    {
                                        "label": "Quinq. séq. (2 et 3)",
                                        "value": rec.rev_5ys23,
                                    },
                                ],
                                "area": True,
                                "title": "",
                                "key": "Nombre de révisions",
                            }
                        ]
                    )
    
                if rec.dash_type == 4:
                    rec.graph_values = json.dumps(
                        [
                            {
                                "values": [
                                    {
                                        "label": "Développement (hrs)",
                                        "value": rec.act_dev,
                                    },
                                    {"label": "Suivi (hrs)", "value": rec.act_acc},
                                    {
                                        "label": "Révision (hrs)",
                                        "value": rec.act_rev,
                                    },
                                    {
                                        "label": "Formation (hrs)",
                                        "value": rec.act_for,
                                    },
                                ],
                                "area": True,
                                "title": "",
                                "key": "Découpage de l'activité",
                            }
                        ]
                    )
    
        # ------------------------------------------------------
        # Calcul le % de révision réalisé
        # ------------------------------------------------------
        def _compute_percent_rev(self):
            for rec in self:
                if rec.rev_total == 0:
                    rec.rev_percent_done = 0
                else:
                    rec.rev_percent_done = rec.rev_done / rec.rev_total * 100
    
        # ------------------------------------------------------
        # Calcul le % d'accompagnement réalisé
        # ------------------------------------------------------
        def _compute_act_acc(self):
            for rec in self:
                if rec.act_acc_theo == 0:
                    rec.act_acc_percent_done = 0
                else:
                    rec.act_acc_percent_done = rec.act_acc / rec.act_acc_theo * 100
    
        # ------------------------------------------------------
        # Affichage des projets de l'ur
        # ------------------------------------------------------
        def show_projets(self):
            return {
                "name": "Prospects",
                "type": "ir.actions.act_window",
                "res_model": "res.partner",
                "view_mode": "kanban,tree,form",
                "views": [
                    (
                        self.env.ref("cgscop_partner.view_partner_cooperative_kanban").id,
                        "kanban",
                    ),
                    (
                        self.env.ref("cgscop_partner.view_partner_prospect_tree").id,
                        "tree",
                    ),
                    (
                        self.env.ref("cgscop_partner.scop_contact_view_form").id,
                        "form",
                    ),
                ],
                "target": "current",
                "domain": [
                    ("is_cooperative", "=", True),
                    (
                        "project_status",
                        "in",
                        (
                            "1_information",
                            "2_pre-diagnostic",
                            "3_accompagnement",
                            "4_adhesion",
                            "5_cg",
                            "7_abandonne",
                        ),
                    ),
                    ("current_user_ur_id", "=", "ur_id"),
                ],
                "context": {
                    "default_is_company": True,
                    "default_is_cooperative": True,
                    "default_company_type": "company",
                    "default_project_status": "1_information",
                },
            }
    
        # ------------------------------------------------------
        # Affichage de tous les projets
        # ------------------------------------------------------
        def show_all_projets(self):
            return {
                "name": "Tous les Prospects",
                "type": "ir.actions.act_window",
                "res_model": "res.partner",
                "view_mode": "kanban,tree,form",
                "views": [
                    (
                        self.env.ref("cgscop_partner.view_partner_cooperative_kanban").id,
                        "kanban",
                    ),
                    (
                        self.env.ref("cgscop_partner.view_partner_prospect_tree").id,
                        "tree",
                    ),
                    (
                        self.env.ref("cgscop_partner.scop_contact_view_form").id,
                        "form",
                    ),
                ],
                "target": "current",
                "domain": [
                    ("is_cooperative", "=", True),
                    (
                        "project_status",
                        "in",
                        (
                            "1_information",
                            "2_pre-diagnostic",
                            "3_accompagnement",
                            "4_adhesion",
                            "5_cg",
                            "7_abandonne",
                        ),
                    ),
                ],
                "context": {
                    "default_is_company": True,
                    "default_is_cooperative": True,
                    "default_company_type": "company",
                    "default_project_status": "1_information",
                },
            }
    
        # ------------------------------------------------------
        # Affichage des coop adh de l'ur
        # ------------------------------------------------------
        def show_coop(self):
            return {
                "name": "Coopératives adhérentes",
                "type": "ir.actions.act_window",
                "res_model": "res.partner",
                "search_view_id": (
                    self.env.ref("cgscop_partner.scop_partner_view_search").id,
                ),
                "view_mode": "tree,form",
                "views": [
                    (
                        self.env.ref("cgscop_partner.view_partner_cooperative_tree").id,
                        "tree",
                    ),
                    (
                        self.env.ref("cgscop_partner.scop_contact_view_form").id,
                        "form",
                    ),
                ],
                "target": "current",
                "domain": [
                    ("is_cooperative", "=", True),
                    ("membership_status", "=", "member"),
                    ("current_user_ur_id", "=", "ur_id"),
                ],
                "context": {
                    "default_is_company": True,
                    "default_is_cooperative": True,
                    "default_company_type": "company",
                    "create": False,
                },
            }
    
        # ------------------------------------------------------
        # Affichage de toutes les coop adh
        # ------------------------------------------------------
        def show_all_coop(self):
            return {
                "name": "Toutes les coopératives adhérentes",
                "type": "ir.actions.act_window",
                "res_model": "res.partner",
                "search_view_id": (
                    self.env.ref("cgscop_partner.scop_partner_view_search").id,
                ),
                "view_mode": "tree,form",
                "views": [
                    (
                        self.env.ref("cgscop_partner.view_partner_cooperative_tree").id,
                        "tree",
                    ),
                    (
                        self.env.ref("cgscop_partner.scop_contact_view_form").id,
                        "form",
                    ),
                ],
                "target": "current",
                "domain": [
                    ("is_cooperative", "=", True),
                    ("membership_status", "=", "member"),
                ],
                "context": {
                    "default_is_company": True,
                    "default_is_cooperative": True,
                    "default_company_type": "company",
                    "create": False,
                },
            }
    
        # ------------------------------------------------------
        # Affichage des coop à réviser
        # ------------------------------------------------------
        def show_rev(self):
    
            wyear = datetime.datetime.today().year
    
            return {
                "name": "Coopérative à réviser",
                "type": "ir.actions.act_window",
                "res_model": "res.partner",
                "view_mode": "tree",
                "views": [
                    (
                        self.env.ref("cgscop_partner.view_partner_cooperative_tree").id,
                        "tree",
                    ),
                    (
                        self.env.ref("cgscop_partner.scop_contact_view_form").id,
                        "form",
                    ),
                ],
                "target": "current",
                "domain": [
                    ("is_cooperative", "=", True),
                    ("membership_status", "=", "member"),
                    ("current_user_ur_id", "=", "ur_id"),
                    ("revision_next_year", "<=", wyear),
                ],
                "context": {
                    "default_is_company": True,
                    "default_is_cooperative": True,
                    "default_company_type": "company",
                    "create": False,
                },
            }
    
        # ------------------------------------------------------
        # Affichage des coop à suivre
        # ------------------------------------------------------
        def show_acc(self):
    
            return {
                "name": "Coopérative à suivre",
                "type": "ir.actions.act_window",
                "res_model": "res.partner",
                "search_view_id": (
                    self.env.ref("cgscop_partner.scop_partner_view_search").id,
                ),
                "view_mode": "tree",
                "views": [
                    (
                        self.env.ref("cgscop_partner_crm.scop_partner_crm_view_tree").id,
                        "tree",
                    ),
                    (
                        self.env.ref("cgscop_partner.scop_contact_view_form").id,
                        "form",
                    ),
                ],
                "target": "current",
                "domain": [
                    ("is_cooperative", "=", True),
                    ("membership_status", "=", "member"),
                    ("current_user_ur_id", "=", "ur_id"),
                ],
                "context": {
                    "default_is_company": True,
                    "default_is_cooperative": True,
                    "default_company_type": "company",
                    "create": False,
                },
            }