im_livechat_channel.py 1.3 KB

1234567891011121314151617181920212223
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. from odoo import models, _
  4. class ImLivechatChannel(models.Model):
  5. _inherit = 'im_livechat.channel'
  6. def _get_livechat_mail_channel_vals(self, anonymous_name, operator=None, chatbot=None, user_id=None, country_id=None):
  7. mail_channel_vals = super(ImLivechatChannel, self)._get_livechat_mail_channel_vals(anonymous_name, operator, chatbot, user_id=user_id, country_id=country_id)
  8. visitor_sudo = self.env['website.visitor']._get_visitor_from_request()
  9. if visitor_sudo:
  10. mail_channel_vals['livechat_visitor_id'] = visitor_sudo.id
  11. # As chat requested by the visitor, delete the chat requested by an operator if any to avoid conflicts between two flows
  12. # TODO DBE : Move this into the proper method (open or init mail channel)
  13. chat_request_channel = self.env['mail.channel'].sudo().search([('livechat_visitor_id', '=', visitor_sudo.id), ('livechat_active', '=', True)])
  14. for mail_channel in chat_request_channel:
  15. operator_name = operator.name if operator else chatbot.operator_partner_id.name
  16. mail_channel._close_livechat_session(cancel=True, operator=operator_name)
  17. return mail_channel_vals