diff --git a/__manifest__.py b/__manifest__.py index 1f6e864d7d46bc8d466ec4b64d355091b9ba6b53..abce1aaf532bae9c7a08a344f0180979dc136580 100644 --- a/__manifest__.py +++ b/__manifest__.py @@ -3,7 +3,7 @@ 'summary': "Dashboard coopératives", 'author': "CGSCOP", 'version': '12.0.0.0', - 'depends': ["cgscop_partner",], + 'depends': ["cgscop_partner","cgscop_partner_crm","cgscop_timesheet"], 'data': [ "security/ir.model.access.csv", "security/security_rules.xml", diff --git a/models/partner_dashboard_dlg.py b/models/partner_dashboard_dlg.py index d238ad96e112d90e0b898de33be4d69830491bc9..021c61b084a5987348171b835329c9dfb61ba0a9 100644 --- a/models/partner_dashboard_dlg.py +++ b/models/partner_dashboard_dlg.py @@ -43,6 +43,21 @@ class ScopPartnerDashboardDlg(models.Model): "Réalisés", compute="_compute_percent_rev") + act_dev = fields.Integer("Développement (hrs)") + act_acc = fields.Integer("Accompagnement (hrs)") + act_rev = fields.Integer("Révision (hrs)") + act_for = fields.Integer("Formation (hrs)") + act_acc_theo = fields.Integer("Acc. théorique (hrs)") + + 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") @@ -56,8 +71,9 @@ class ScopPartnerDashboardDlg(models.Model): qy_projet = self._select_projet() qy_coop = self._select_coop() qy_rev = self._select_rev() + qy_act = self._select_act() - qy = qy_projet + " UNION ALL " + qy_coop + " UNION ALL " + qy_rev + qy = qy_projet + " UNION ALL " + qy_coop + " UNION ALL " + qy_rev + " UNION ALL " + qy_act return qy @@ -91,7 +107,12 @@ class ScopPartnerDashboardDlg(models.Model): 0 as rev_5ys, 0 as rev_5ys23, 0 as rev_todo, - 0 as rev_total + 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 @@ -145,7 +166,12 @@ class ScopPartnerDashboardDlg(models.Model): 0 as rev_5ys, 0 as rev_5ys23, 0 as rev_todo, - 0 as rev_total + 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 @@ -192,7 +218,12 @@ class ScopPartnerDashboardDlg(models.Model): 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 + 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 @@ -222,6 +253,127 @@ class ScopPartnerDashboardDlg(models.Model): """ return query + # ------------------------------------------------------ + # Dashboard activité + # ------------------------------------------------------ + @api.model + def _select_act(self): + + query = """ + SELECT + CONCAT('4', wrk.dlg_id) as id, + dlg_id, + CONCAT('Activité année ',date_part('year', CURRENT_DATE)) AS name, + '4' as dash_type, + 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.user_id as dlg_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.user_id as dlg_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.user_id as dlg_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.user_id as dlg_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.followup_delegate_id as dlg_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.dlg_id, + wrk.year + """ + return query + def init(self): tools.drop_view_if_exists(self.env.cr, self._table) @@ -276,6 +428,19 @@ class ScopPartnerDashboardDlg(models.Model): '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é # ------------------------------------------------------ @@ -287,6 +452,17 @@ class ScopPartnerDashboardDlg(models.Model): else: rec.rev_percent_done = rec.rev_done / rec.rev_total * 100 + # ------------------------------------------------------ + # Calcul le % d'accompagnement réalisé + # ------------------------------------------------------ + @api.multi + 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 # ------------------------------------------------------ @@ -352,4 +528,28 @@ class ScopPartnerDashboardDlg(models.Model): ('revision_person_id', '=', self.env.user.id), ('revision_next_year', '=', wyear) ], + } + + # ------------------------------------------------------ + # Affichage des coop à suivre + # ------------------------------------------------------ + def show_acc(self): + + wyear = datetime.datetime.today().year + + 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_type': 'form', + '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'), + ('followup_delegate_id', '=', self.env.user.id)], } \ No newline at end of file diff --git a/models/partner_dashboard_ur.py b/models/partner_dashboard_ur.py index 049c262cb3c30189b69ef2252a4c013510c27cfc..f03008b5fafd41e02c165e5f233b591968ece5bf 100644 --- a/models/partner_dashboard_ur.py +++ b/models/partner_dashboard_ur.py @@ -50,6 +50,15 @@ class ScopPartnerDashboardUr(models.Model): "Réalisés", 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") # ------------------------------------------------------ @@ -68,8 +77,9 @@ class ScopPartnerDashboardUr(models.Model): 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 = qy_projet + " UNION ALL " + qy_coop + " UNION ALL " + qy_rev + qy = qy_projet + " UNION ALL " + qy_coop + " UNION ALL " + qy_rev + " UNION ALL " + qy_act return qy @@ -104,7 +114,12 @@ class ScopPartnerDashboardUr(models.Model): 0 as rev_5ys, 0 as rev_5ys23, 0 as rev_todo, - 0 as rev_total + 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 @@ -138,7 +153,12 @@ class ScopPartnerDashboardUr(models.Model): 0 as rev_5ys, 0 as rev_5ys23, 0 as rev_todo, - 0 as rev_total + 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 @@ -192,7 +212,12 @@ class ScopPartnerDashboardUr(models.Model): 0 as rev_5ys, 0 as rev_5ys23, 0 as rev_todo, - 0 as rev_total + 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 @@ -230,7 +255,12 @@ class ScopPartnerDashboardUr(models.Model): 0 as rev_5ys, 0 as rev_5ys23, 0 as rev_todo, - 0 as rev_total + 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 @@ -277,7 +307,12 @@ class ScopPartnerDashboardUr(models.Model): 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 + 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 @@ -307,6 +342,129 @@ class ScopPartnerDashboardUr(models.Model): """ return query + + # ------------------------------------------------------ + # Dashboard activité + # ------------------------------------------------------ + @api.model + def _select_act(self, cgscop_id): + + query = """ + SELECT + CONCAT('4', ur_id) as id, + 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 ( @@ -367,6 +525,19 @@ class ScopPartnerDashboardUr(models.Model): '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é # ------------------------------------------------------ @@ -378,6 +549,17 @@ class ScopPartnerDashboardUr(models.Model): else: rec.rev_percent_done = rec.rev_done / rec.rev_total * 100 + # ------------------------------------------------------ + # Calcul le % d'accompagnement réalisé + # ------------------------------------------------------ + @api.multi + 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 # ------------------------------------------------------ @@ -483,3 +665,27 @@ class ScopPartnerDashboardUr(models.Model): ('current_user_ur_id', '=', 'ur_id'), ('revision_next_year', '=', wyear)], } + + # ------------------------------------------------------ + # Affichage des coop à suivre + # ------------------------------------------------------ + def show_acc(self): + + wyear = datetime.datetime.today().year + + 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_type': 'form', + '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')], + } \ No newline at end of file diff --git a/views/partner_dashboard_dlg.xml b/views/partner_dashboard_dlg.xml index eabdf5766ddc8838d5f89954f54a5b1336273f99..9e61ffc4fe1c0642a3588e21088c6c00c858a6c2 100644 --- a/views/partner_dashboard_dlg.xml +++ b/views/partner_dashboard_dlg.xml @@ -125,6 +125,33 @@ </div> </div> + <!-- Affiche Dashboard type 4 --> + <div class="row" attrs="{'invisible': [('dash_type', '!=', 4)]}"> + <div class="col-6"> + <div class="text-center mb32"> + <button type="object" name="show_acc" class="btn btn-info">Voir les coopératives<br/> à suivre</button> + </div> + <div class="text-center"> + <field name="act_acc_percent_done" widget="percentpie"/> + </div> + </div> + <div class="col-6"> + <table class="table table-bordered"> + <tbody> + <tr> + <td>Suivi à réaliser (hrs) :</td> + <td><field name="act_acc_theo"/></td> + </tr> + <tr> + <td>Suivi réalisés (hrs) :</td> + <td><field name="act_acc"/></td> + </tr> + </tbody> + </table> + </div> + </div> + + <!-- Affiche le graph --> <div class="row"> <div class="col"> diff --git a/views/partner_dashboard_ur.xml b/views/partner_dashboard_ur.xml index 777f1726af4d1ce21b0135f3995c95a539e60be7..48e10fe21cd5b5a4bb325caf3c88c93c9db03d26 100644 --- a/views/partner_dashboard_ur.xml +++ b/views/partner_dashboard_ur.xml @@ -132,6 +132,33 @@ </div> </div> + <!-- Affiche Dashboard type 4 --> + <div class="row" attrs="{'invisible': [('dash_type', '!=', 4)]}"> + <div class="col-6"> + <div class="text-center mb32"> + <button type="object" name="show_acc" class="btn btn-info">Voir les coopératives<br/> à suivre</button> + </div> + <div class="text-center"> + <field name="act_acc_percent_done" widget="percentpie"/> + </div> + </div> + <div class="col-6"> + <table class="table table-bordered"> + <tbody> + <tr> + <td>Suivi à réaliser (hrs) :</td> + <td><field name="act_acc_theo"/></td> + </tr> + <tr> + <td>Suivi réalisés (hrs) :</td> + <td><field name="act_acc"/></td> + </tr> + </tbody> + </table> + </div> + </div> + + <!-- Affiche le graph --> <div class="row"> <div class="col">