diff options
| author | Kaushalya Mandaliya <kma@odoo.com> | 2019-05-07 12:18:23 +0000 |
|---|---|---|
| committer | Barad Mahendra <mba@openerp.com> | 2019-06-06 04:45:21 +0000 |
| commit | 7a3a1a43b3144bb25a3d72c9702fc243e55734b3 (patch) | |
| tree | 99381ff46597ff35793c977ab5662d3636884aa8 /addons | |
| parent | 218d5ce6a8229dd37253665c1e6071ea66c01591 (diff) | |
[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: c04b9c019eb4c04d62d1d90b810c5407d8a9b5bd
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>
Diffstat (limited to 'addons')
| -rw-r--r-- | addons/im_livechat/models/im_livechat_channel.py | 9 | ||||
| -rw-r--r-- | addons/im_livechat/tests/test_get_mail_channel.py | 8 |
2 files changed, 14 insertions, 3 deletions
diff --git a/addons/im_livechat/models/im_livechat_channel.py b/addons/im_livechat/models/im_livechat_channel.py index 6a568bbb269..b599738915e 100644 --- a/addons/im_livechat/models/im_livechat_channel.py +++ b/addons/im_livechat/models/im_livechat_channel.py @@ -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, }) diff --git a/addons/im_livechat/tests/test_get_mail_channel.py b/addons/im_livechat/tests/test_get_mail_channel.py index ac3d5807333..2c0106ea37b 100644 --- a/addons/im_livechat/tests/test_get_mail_channel.py +++ b/addons/im_livechat/tests/test_get_mail_channel.py @@ -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 = [] |
