[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
This commit is contained in:
@@ -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)'
|
||||
|
||||
@@ -108,6 +108,18 @@
|
||||
string="Accept Emails From"
|
||||
attrs="{'invisible': [('use_leads', '=', False), ('use_opportunities', '=', False)]}"/>
|
||||
</xpath>
|
||||
<field name="dashboard_graph_period" position="attributes">
|
||||
<attribute name="attrs">{'invisible': [('dashboard_graph_model', '=', 'pipeline')]}</attribute>
|
||||
</field>
|
||||
<field name="dashboard_graph_period" position="after">
|
||||
<field name="dashboard_graph_period_pipeline" attrs="{'invisible': [('dashboard_graph_model', '!=', 'pipeline')]}"/>
|
||||
</field>
|
||||
<field name="dashboard_graph_group" position="attributes">
|
||||
<attribute name="attrs">{'invisible': [('dashboard_graph_model', '=', 'pipeline')]}</attribute>
|
||||
</field>
|
||||
<field name="dashboard_graph_group" position="after">
|
||||
<field name="dashboard_graph_group_pipeline" attrs="{'invisible': [('dashboard_graph_model', '!=', 'pipeline')]}"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
@@ -6,10 +6,10 @@
|
||||
<field name="inherit_id" ref="sales_team.crm_team_view_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='dashboard_graph_model']" position="attributes">
|
||||
<attribute name="attrs">{'invisible': [('team_type', '=', 'pos')]}</attribute>
|
||||
<attribute name="attrs">{'readonly': [('team_type', 'in', ['pos', 'ebay'])]}</attribute>
|
||||
</xpath>
|
||||
<xpath expr="//field[@name='dashboard_graph_group']" position="attributes">
|
||||
<attribute name="attrs">{'invisible': [('team_type', '=', 'pos')]}</attribute>
|
||||
<attribute name="attrs">{'invisible': ['|', ('dashboard_graph_model', '=', 'pipeline'), ('team_type', '=', 'pos')]}</attribute>
|
||||
</xpath>
|
||||
<xpath expr="//field[@name='dashboard_graph_group']" position="after">
|
||||
<field name="dashboard_graph_group_pos" attrs="{'invisible': [('team_type', '!=', 'pos')]}"/>
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -94,7 +94,7 @@
|
||||
</group>
|
||||
</group>
|
||||
<notebook>
|
||||
<page name="members" string="Team Members">
|
||||
<page name="members" string="Team Members" attrs="{'invisible': [('team_type', 'in', ['pos', 'ebay'])]}">
|
||||
<field name="member_ids" options="{'not_delete': True}">
|
||||
<kanban quick_create="false" create="true" delete="true">
|
||||
<field name="id"/>
|
||||
@@ -117,9 +117,9 @@
|
||||
</page>
|
||||
<page string="Dashboard" name="dashboard">
|
||||
<group string="Graph" name="graph">
|
||||
<field name="dashboard_graph_model"/>
|
||||
<field name="dashboard_graph_group"/>
|
||||
<field name="dashboard_graph_model" attrs="{'readonly': [('team_type', 'in', ['pos', 'ebay'])]}"/>
|
||||
<field name="dashboard_graph_period"/>
|
||||
<field name="dashboard_graph_group"/>
|
||||
</group>
|
||||
</page>
|
||||
</notebook>
|
||||
|
||||
Reference in New Issue
Block a user