From 48e843aa8d906d1dc9e2d06e8a6d4e00cab45c59 Mon Sep 17 00:00:00 2001 From: dut-odoo Date: Mon, 23 Jan 2017 10:56:49 +0530 Subject: [PATCH] [IMP] sales_team: improve sale channel settings Current sales channel configuration for graphs is complicated for users. This commit attempts to simplify the form view by renaming labels on selections depending on the chosen graph model. It also adds the option to group by stage for the pipeline graph and hides the team members for the POS and eBay sales channel. - swap `groupby` with `period` - for `sale` and `invoice` graphs: - rename label: `period` -> `scale` - rename graph periods' selection items: `This Month/ This Week/ This Year` -> `Last Month/ Last Week/ Last Year` - for `pipeline` graph: - rename label: `period` -> `expected to close` - rename graph periods' selection items: `This Month/ This Week/ This Year` -> `Within a Month/ Within a Week/ Within a Year` - rename graph groupbys: `Day/Week/Month` -> `Expected Closing Day/ Expected Closing Week/ Expected Closing Month` - add new graph groupby: `Stage` - remove lead management fields for ebay and pos channels - hide `Assignation` page and `Domain`, `Assigned Leads Count` and `Minimum Score` fields - in dashboard page, make content field readonly --- addons/crm/models/crm_team.py | 53 ++++++++++++++++++++++ addons/crm/views/crm_team_views.xml | 12 +++++ addons/pos_sale/views/sales_team_views.xml | 4 +- addons/sales_team/models/crm_team.py | 8 ++-- addons/sales_team/views/crm_team_views.xml | 6 +-- 5 files changed, 74 insertions(+), 9 deletions(-) diff --git a/addons/crm/models/crm_team.py b/addons/crm/models/crm_team.py index 9480eaa150d..b16efe51e0a 100644 --- a/addons/crm/models/crm_team.py +++ b/addons/crm/models/crm_team.py @@ -25,6 +25,19 @@ class Team(models.Model): compute='_compute_opportunities', string='Amount of quotations to invoice', readonly=True) dashboard_graph_model = fields.Selection(selection_add=[('pipeline', 'Pipeline')]) + dashboard_graph_period_pipeline = fields.Selection([ + ('week', 'Within a Week'), + ('month', 'Within a Month'), + ('year', 'Within a Year'), + ], string='Expected to Close', help="The time period this channel's dashboard graph will consider.", + compute="_compute_dashboard_graph_period_pipeline", inverse="_inverse_dashboard_graph_period_pipeline") + dashboard_graph_group_pipeline = fields.Selection([ + ('day', 'Expected Closing Day'), + ('week', 'Expected Closing Week'), + ('month', 'Expected Closing Month'), + ('user', 'Salesperson'), + ('stage', 'Stage'), + ], string='Group by', default='day', help="How this channel's dashboard graph will group the results.") def _compute_unassigned_leads_count(self): leads_data = self.env['crm.lead'].read_group([ @@ -48,6 +61,14 @@ class Team(models.Model): team.opportunities_count = counts.get(team.id, 0) team.opportunities_amount = amounts.get(team.id, 0) + def _compute_dashboard_graph_period_pipeline(self): + for channel in self: + channel.dashboard_graph_period_pipeline = channel.dashboard_graph_period + + def _inverse_dashboard_graph_period_pipeline(self): + for channel in self.filtered(lambda ch: ch.dashboard_graph_model == 'pipeline'): + channel.dashboard_graph_period = channel.dashboard_graph_period_pipeline + def get_alias_model_name(self, vals): return 'crm.lead' @@ -77,6 +98,23 @@ class Team(models.Model): self.use_leads = False return super(Team, self)._onchange_team_type() + @api.onchange('dashboard_graph_model') + def _onchange_dashboard_graph_model(self): + if self.dashboard_graph_model == 'pipeline': + self.dashboard_graph_period_pipeline = self.dashboard_graph_period + self.dashboard_graph_group_pipeline = self.dashboard_graph_group + else: + self.dashboard_graph_period = self.dashboard_graph_period_pipeline + if not self.dashboard_graph_group: + self.dashboard_graph_group = self._fields['dashboard_graph_group'].default(self) + + @api.onchange('dashboard_graph_group_pipeline') + def _onchange_dashboard_graph_group_pipeline(self): + if self.dashboard_graph_group_pipeline == 'stage': + self.dashboard_graph_group = False + else: + self.dashboard_graph_group = self.dashboard_graph_group_pipeline + @api.constrains('dashboard_graph_model', 'use_opportunities') def _check_graph_model(self): if not self.use_opportunities and self.dashboard_graph_model == 'pipeline': @@ -170,11 +208,26 @@ class Team(models.Model): return [start_date, end_date] return super(Team, self)._graph_get_dates(today) + def _get_graph(self): + graph_datas = super(Team, self)._get_graph() + if self.dashboard_graph_model == 'pipeline' and self.dashboard_graph_group_pipeline == 'stage': + stage_data = self.env['crm.stage'].browse([d['label'] for d in graph_datas[0]['values']]).read(['sequence', 'name']) + stage_data = {d['id']: {'name': d['name'], 'sequence': d['sequence']} for d in stage_data} + graph_datas[0]['values'] = sorted(graph_datas[0]['values'], key=lambda el: stage_data[el['label']]['sequence']) + for gdata in graph_datas[0]['values']: + gdata['label'] = stage_data[gdata['label']]['name'] + return graph_datas + def _graph_date_column(self): if self.dashboard_graph_model == 'pipeline': return 'date_deadline' return super(Team, self)._graph_date_column() + def _graph_x_query(self): + if self.dashboard_graph_model == 'pipeline' and self.dashboard_graph_group_pipeline == 'stage': + return 'stage_id' + return super(Team, self)._graph_x_query() + def _graph_y_query(self): if self.dashboard_graph_model == 'pipeline': return 'SUM(expected_revenue)' diff --git a/addons/crm/views/crm_team_views.xml b/addons/crm/views/crm_team_views.xml index 23698ecc36c..94320c9c0e8 100644 --- a/addons/crm/views/crm_team_views.xml +++ b/addons/crm/views/crm_team_views.xml @@ -108,6 +108,18 @@ string="Accept Emails From" attrs="{'invisible': [('use_leads', '=', False), ('use_opportunities', '=', False)]}"/> + + {'invisible': [('dashboard_graph_model', '=', 'pipeline')]} + + + + + + {'invisible': [('dashboard_graph_model', '=', 'pipeline')]} + + + + diff --git a/addons/pos_sale/views/sales_team_views.xml b/addons/pos_sale/views/sales_team_views.xml index 0ecb5c08140..13f79a22e16 100644 --- a/addons/pos_sale/views/sales_team_views.xml +++ b/addons/pos_sale/views/sales_team_views.xml @@ -6,10 +6,10 @@ - {'invisible': [('team_type', '=', 'pos')]} + {'readonly': [('team_type', 'in', ['pos', 'ebay'])]} - {'invisible': [('team_type', '=', 'pos')]} + {'invisible': ['|', ('dashboard_graph_model', '=', 'pipeline'), ('team_type', '=', 'pos')]} diff --git a/addons/sales_team/models/crm_team.py b/addons/sales_team/models/crm_team.py index a085622fc47..131ff1fd745 100644 --- a/addons/sales_team/models/crm_team.py +++ b/addons/sales_team/models/crm_team.py @@ -65,10 +65,10 @@ class CrmTeam(models.Model): ('user', 'Salesperson'), ], string='Group by', default='day', help="How this channel's dashboard graph will group the results.") dashboard_graph_period = fields.Selection([ - ('week', 'This Week'), - ('month', 'This Month'), - ('year', 'This Year'), - ], string='Period', default='month', help="The time period this channel's dashboard graph will consider.") + ('week', 'Last Week'), + ('month', 'Last Month'), + ('year', 'Last Year'), + ], string='Scale', default='month', help="The time period this channel's dashboard graph will consider.") @api.depends('dashboard_graph_group', 'dashboard_graph_model', 'dashboard_graph_period') def _compute_dashboard_graph(self): diff --git a/addons/sales_team/views/crm_team_views.xml b/addons/sales_team/views/crm_team_views.xml index bd2b9f552e0..73e34493902 100644 --- a/addons/sales_team/views/crm_team_views.xml +++ b/addons/sales_team/views/crm_team_views.xml @@ -94,7 +94,7 @@ - + @@ -117,9 +117,9 @@ - - + +