[FIX] im_livechat: correctly display known partner name

When talking via the Live Chat to a known partner, should be able to see
his name in the chat window title, from the commit: c04b9c019e
the partner name wasn't showing in the title as sudo is being used.

After this commit, known partner name will be shown in the
Live Chat window title.

And improving a test case, in which we're checking for the known partner's
name in the chat window title.

task-1940407

closes odoo/odoo#33831

Signed-off-by: Martin Geubelle (mge) <mge@openerp.com>
This commit is contained in:
Kaushalya Mandaliya
2019-06-06 04:45:21 +00:00
committed by Barad Mahendra
parent 218d5ce6a8
commit 7a3a1a43b3
2 changed files with 14 additions and 3 deletions
@@ -162,8 +162,11 @@ class ImLivechatChannel(models.Model):
operator_partner_id = operator.partner_id.id
# partner to add to the mail.channel
channel_partner_to_add = [(4, operator_partner_id)]
if self.env.user and self.env.user.active: # valid session user (not public)
channel_partner_to_add.append((4, self.env.user.partner_id.id))
visitor_user = False
if user_id:
visitor_user = self.env['res.users'].browse(user_id)
if visitor_user and visitor_user.active: # valid session user (not public)
channel_partner_to_add.append((4, visitor_user.partner_id.id))
# create the session, and add the link with the given channel
mail_channel = self.env["mail.channel"].with_context(mail_create_nosubscribe=False).sudo().create({
'channel_partner_ids': channel_partner_to_add,
@@ -172,7 +175,7 @@ class ImLivechatChannel(models.Model):
'anonymous_name': False if user_id else anonymous_name,
'country_id': country_id,
'channel_type': 'livechat',
'name': ', '.join([self.env['res.users'].browse(user_id).name if user_id else anonymous_name, operator.livechat_username if operator.livechat_username else operator.name]),
'name': ', '.join([visitor_user.name if visitor_user else anonymous_name, operator.livechat_username if operator.livechat_username else operator.name]),
'public': 'private',
'email_send': False,
})
@@ -24,6 +24,11 @@ class TestGetMailChannel(TransactionCase):
'login': 'georges'
}])
self.visitor_user = self.env['res.users'].create({
'name': 'Rajesh',
'login': 'rajesh',
})
self.livechat_channel = self.env['im_livechat.channel'].create({
'name': 'The channel',
'user_ids': (6, 0, self.operators.ids)
@@ -46,6 +51,9 @@ class TestGetMailChannel(TransactionCase):
channel_operator_ids = [channel_operator[0] for channel_operator in channel_operators]
self.assertTrue(all(partner_id in channel_operator_ids for partner_id in self.operators.mapped('partner_id').ids))
visitor_user_channel = self.livechat_channel._get_mail_channel('Visitor', user_id=self.visitor_user.id)
self.assertEqual(visitor_user_channel['correspondent_name'], self.visitor_user.name, "Chat title should be correct")
def _get_mail_channels(self):
mail_channels = []