summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Ledoux <dle@odoo.com>2018-11-29 11:33:49 +0000
committerDenis Ledoux <dle@odoo.com>2018-11-29 11:46:22 +0000
commit9fbac5fcbbec20777a15a46fe17a6eb7e21575d4 (patch)
treea432ec0250f4c2bb21923b91ef241a95fbdd5f10
parent8e7c2552371fddcb5cd9ef1e785ec40c37fe8ea0 (diff)
[IMP] crm: improve team pipeline dashboard leads/opps counts performance
The team pipeline dashboard fields `unassigned_leads_count`, `opportunities_count`, `opportunities_amount` do a big search on leads, filtered by type (lead/opp), team, and unassigned user_id (salesman) Adding an index on user_id, team_id, type significantly improves the filtering, and therefore the dashboard rendering, especially when displaying a few teams only e.g; the teams you are part or responsible of. The index on `user_id` is removed, as it become a duplicate as `user_id` is the first column of this new index.
-rw-r--r--addons/crm/models/crm_lead.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/addons/crm/models/crm_lead.py b/addons/crm/models/crm_lead.py
index 679cf8a3247..7fa44b31bfd 100644
--- a/addons/crm/models/crm_lead.py
+++ b/addons/crm/models/crm_lead.py
@@ -88,7 +88,7 @@ class Lead(models.Model):
stage_id = fields.Many2one('crm.stage', string='Stage', ondelete='restrict', track_visibility='onchange', index=True,
domain="['|', ('team_id', '=', False), ('team_id', '=', team_id)]",
group_expand='_read_group_stage_ids', default=lambda self: self._default_stage_id())
- user_id = fields.Many2one('res.users', string='Salesperson', index=True, track_visibility='onchange', default=lambda self: self.env.user)
+ user_id = fields.Many2one('res.users', string='Salesperson', track_visibility='onchange', default=lambda self: self.env.user)
referred = fields.Char('Referred By')
date_open = fields.Datetime('Assignation Date', readonly=True, default=fields.Datetime.now)
@@ -133,6 +133,13 @@ class Lead(models.Model):
('check_probability', 'check(probability >= 0 and probability <= 100)', 'The probability of closing the deal should be between 0% and 100%!')
]
+ @api.model_cr_context
+ def _auto_init(self):
+ res = super(Lead, self)._auto_init()
+ tools.create_index(self._cr, 'crm_lead_user_id_team_id_type_index',
+ self._table, ['user_id', 'team_id', 'type'])
+ return res
+
@api.model
def _read_group_stage_ids(self, stages, domain, order):
# retrieve team_id from the context and write the domain