[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.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user