[FIX] website_livechat, im_livechat : use visitor display name instead of name
As since 5b9a81a2c6
website.visitor.name can be null
if the visitor is not linked to a lead or a res.partner,
we cannot use the name anymore to build the name of the mail.channel, etc..
Using display_name will always return the correct value,
and will include the numbering of the visitor,
in order to identify easily the chat windows
(if operator is speaking with multi visitor at the same time)
Task ID: 2076190
PR #37340
This commit is contained in:
@@ -120,7 +120,7 @@ class ImLivechatChannel(models.Model):
|
||||
'anonymous_name': False if user_id else anonymous_name,
|
||||
'country_id': country_id,
|
||||
'channel_type': 'livechat',
|
||||
'name': ', '.join([visitor_user.name if visitor_user else anonymous_name, operator.livechat_username if operator.livechat_username else operator.name]),
|
||||
'name': ', '.join([visitor_user.display_name if visitor_user else anonymous_name, operator.livechat_username if operator.livechat_username else operator.name]),
|
||||
'public': 'private',
|
||||
'email_send': False,
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ class TestGetMailChannel(TransactionCase):
|
||||
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._open_livechat_mail_channel('Visitor', user_id=self.visitor_user.id)
|
||||
chat_title = '%s (%s)' % (self.visitor_user.name, self.visitor_user.country_id.name)
|
||||
chat_title = '%s (%s)' % (self.visitor_user.display_name, self.visitor_user.country_id.name)
|
||||
self.assertEqual(visitor_user_channel['correspondent_name'], chat_title, "Chat title should be correct and should contain visitor's country name")
|
||||
|
||||
def _open_livechat_mail_channel(self):
|
||||
|
||||
@@ -16,7 +16,7 @@ class ImLivechatChannel(models.Model):
|
||||
'livechat_active': True
|
||||
})
|
||||
if not user_id:
|
||||
mail_channel_vals['anonymous_name'] = visitor_sudo.name + (' (%s)' % visitor_sudo.country_id.name if visitor_sudo.country_id else '')
|
||||
mail_channel_vals['anonymous_name'] = visitor_sudo.display_name + (' (%s)' % visitor_sudo.country_id.name if visitor_sudo.country_id else '')
|
||||
# As chat requested by the visitor, delete the chat requested by an operator if any to avoid conflicts between two flows
|
||||
chat_request_channel = self.env['mail.channel'].sudo().search([('livechat_visitor_id', '=', visitor_sudo.id), ('livechat_active', '=', True)])
|
||||
for mail_channel in chat_request_channel:
|
||||
|
||||
@@ -34,7 +34,7 @@ class MailChannel(models.Model):
|
||||
visitor = channel.livechat_visitor_id
|
||||
if visitor:
|
||||
channel_infos_dict[channel.id]['visitor'] = {
|
||||
'name': visitor.name,
|
||||
'name': visitor.display_name,
|
||||
'country_code': visitor.country_id.code.lower() if visitor.country_id else False,
|
||||
'is_connected': visitor.is_connected,
|
||||
'history': self._get_visitor_history(visitor),
|
||||
@@ -67,7 +67,7 @@ class MailChannel(models.Model):
|
||||
if not self.channel_message_ids:
|
||||
return
|
||||
# Notify that the visitor has left the conversation
|
||||
name = _('The visitor') if not self.livechat_visitor_id else self.livechat_visitor_id.name
|
||||
name = _('The visitor') if not self.livechat_visitor_id else self.livechat_visitor_id.display_name
|
||||
if type == 'cancel':
|
||||
message = _('has started a conversation with %s. The chat request has been canceled.') % kwargs.get('speaking_with', 'an operator')
|
||||
else:
|
||||
|
||||
@@ -54,7 +54,7 @@ class WebsiteVisitor(models.Model):
|
||||
for visitor in self:
|
||||
operator = self.env.user
|
||||
country = visitor.country_id
|
||||
visitor_name = "%s (%s)" % (visitor.name, country.name) if country else visitor.name
|
||||
visitor_name = "%s (%s)" % (visitor.display_name, country.name) if country else visitor.display_name
|
||||
mail_channel_vals_list.append({
|
||||
'channel_partner_ids': [(4, operator.partner_id.id)],
|
||||
'livechat_channel_id': visitor.website_id.channel_id.id,
|
||||
|
||||
Reference in New Issue
Block a user