The purpose of this commit is to improve the overall performance of the mention
mechanism of the client action and chatter composer, by pre-fetching some data.
First, the employees are fetched at chat initialization (basically, at web
client initialization), if hr is installed.
Second, when focusing on the composer of a channel, the members of this channel
are fetched. In the case of a chatter, the members are already known as they
are the followers of the document.
When the user types a mention, we first display suggestions from the pre-fetched
partners, and we only perform an RPC when there are no more result matching the
search string. This RPC searches among user, and then partners if there aren't
enough matches.
A few side changes occurred:
- auto_join set to True on user_ids field of res.partner to boost the query
that searches partners that are users
- the '/mail/read_followers' route now returns follower's email as well, as
we need it for the mention;
- a partner can now be mentionned several times in the same message;
- mentionned partner previsualization has been removed, mainly because of
the previous point, but also because it simplifies the code;
23 lines
821 B
Python
23 lines
821 B
Python
# -*- coding: utf-8 -*-
|
|
|
|
from openerp import api, models
|
|
|
|
class Partner(models.Model):
|
|
_name = "res.partner"
|
|
_inherit = ['res.partner']
|
|
|
|
@api.model
|
|
def get_static_mention_suggestions(self):
|
|
""" Extend the mail's static mention suggestions by adding the employees. """
|
|
suggestions = super(Partner, self).get_static_mention_suggestions()
|
|
|
|
employee_group_id = self.env['ir.model.data'].xmlid_to_res_id('base.group_user')
|
|
self._cr.execute("""
|
|
SELECT P.id, P.name, P.email
|
|
FROM res_users U
|
|
INNER JOIN res_groups_users_rel R ON U.id = R.uid
|
|
INNER JOIN res_partner P ON P.id = U.partner_id
|
|
WHERE R.gid = %s""", (employee_group_id,))
|
|
suggestions.append(self._cr.dictfetchall())
|
|
return suggestions
|