diff --git a/report/partner_dashboard_ur.py b/report/partner_dashboard_ur.py index 7fbb43108fd053661d635a541a4662e41220de2f..b6287750fae7c514fa737d81346f81375c866a3a 100644 --- a/report/partner_dashboard_ur.py +++ b/report/partner_dashboard_ur.py @@ -68,7 +68,7 @@ class ScopPartnerDashboardUr(models.Model): def _select(self): # On récupere l'id de la cgscop cgids = self.env["union.regionale"].search([("name", "ilike", "CGSCOP")]) - if len(cgids) != 1: + if not cgids: cgscop_id = 0 else: cgscop_id = cgids[0].id @@ -79,16 +79,11 @@ class ScopPartnerDashboardUr(models.Model): qy_rev = self._select_rev(cgscop_id) qy_act = self._select_act(cgscop_id) - qy = ( - qy_projet - + " UNION ALL " - + qy_coop - + " UNION ALL " - + qy_rev - + " UNION ALL " - + qy_act - ) - + 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 # ------------------------------------------------------ @@ -98,10 +93,10 @@ class ScopPartnerDashboardUr(models.Model): def _select_projet(self, cgscop_id): query = """ SELECT - CONCAT('1', ur_id) AS id, + CONCAT('1', ur_id) AS id_txt, org.ur_id as ur_id, 'Prospects en cours' AS name, - '1' as dash_type, + 1 as dash_type, 0 as all_ur, SUM(case when substring(org.project_status,1,1) = '1' then 1 @@ -147,10 +142,10 @@ class ScopPartnerDashboardUr(models.Model): org.ur_id UNION ALL SELECT - '1CGSCOP' AS id, + '1CGSCOP' AS id_txt, '%d' as ur_id, 'Prospects en cours' AS name, - '1' as dash_type, + 1 as dash_type, 1 as all_ur, SUM(case when substring(org.project_status,1,1) = '1' then 1 @@ -203,7 +198,6 @@ class ScopPartnerDashboardUr(models.Model): # ------------------------------------------------------ @api.model def _select_coop(self, cgscop_id): - try: form_scop = self.env.ref("cgscop_partner.form_scop").id except Exception: @@ -221,10 +215,10 @@ class ScopPartnerDashboardUr(models.Model): query = """ SELECT - CONCAT('2', ur_id) AS id, + CONCAT('2', ur_id) AS id_txt, org.ur_id as ur_id, 'Coopératives adhérentes' AS name, - '2' as dash_type, + 2 as dash_type, 0 as all_ur, 0 as nb_prj_info, 0 as nb_prj_pdiag, @@ -275,10 +269,10 @@ class ScopPartnerDashboardUr(models.Model): org.ur_id UNION ALL SELECT - '2CGSCOP' AS id, + '2CGSCOP' AS id_txt, '%d' as ur_id, 'Coopératives adhérentes' AS name, - '2' as dash_type, + 2 as dash_type, 1 as all_ur, 0 as nb_prj_info, 0 as nb_prj_pdiag, @@ -342,13 +336,12 @@ class ScopPartnerDashboardUr(models.Model): # ------------------------------------------------------ @api.model def _select_rev(self, cgscop_id): - query = """ SELECT - id, + id_txt, ur_id, CONCAT('Révisions année ',date_part('year', CURRENT_DATE)) AS name, - '3' as dash_type, + 3 as dash_type, 0 as all_ur, 0 as nb_prj_info, 0 as nb_prj_pdiag, @@ -379,7 +372,7 @@ class ScopPartnerDashboardUr(models.Model): FROM ( SELECT - CONCAT(org.ur_id, org.revision_next_year) AS id, + 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, @@ -390,7 +383,7 @@ class ScopPartnerDashboardUr(models.Model): WHERE (org.revision_next_year = date_part('year', CURRENT_DATE)) UNION ALL SELECT - CONCAT(org.ur_id, date_part('year', rev.date)) as id, + 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, @@ -401,7 +394,7 @@ class ScopPartnerDashboardUr(models.Model): 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, wrev.ur_id + GROUP BY wrev.id_txt, wrev.ur_id """ return query @@ -410,13 +403,12 @@ class ScopPartnerDashboardUr(models.Model): # ------------------------------------------------------ @api.model def _select_act(self, cgscop_id): - query = """ SELECT - CONCAT('4', ur_id) as id, + CONCAT('4', ur_id) as id_txt, ur_id, CONCAT('Activité année ',date_part('year', CURRENT_DATE)) AS name, - '4' as dash_type, + 4 as dash_type, 0 as all_ur, 0 as nb_prj_info, 0 as nb_prj_pdiag, @@ -878,8 +870,6 @@ class ScopPartnerDashboardUr(models.Model): # ------------------------------------------------------ def show_acc(self): - datetime.datetime.today().year - return { "name": "Coopérative à suivre", "type": "ir.actions.act_window",