Purpose ======= Several methods of the 'im_livechat.channel' model were passed a 'channel_id' to work on. This has been changed so that the caller can use those methods on an instance of this model instead. Some methods have also been switched to private because they had no apparent reasons to be public. This is a preliminary cleaning for task #1919871 Specicial note for the "loader" template: To load the livechat assets in a website page, the 'loader' template of livechat is directly called (instead of being returned through a controller) in order to avoid a new call to server. As this commit moves 'sudo' to make method callable on the record directly, it still needs to be sudo. First solution was to add the 'sudo' in the template, which is a bad practise. This commit creates a proxy method on website model returning the livechat info with 'sudo'. This avoid having the 'sudo' done in template. Like always, explicit is better than implicit. Task-1919871
22 lines
623 B
Python
22 lines
623 B
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo import api, fields, models
|
|
|
|
|
|
class Website(models.Model):
|
|
|
|
_inherit = "website"
|
|
|
|
channel_id = fields.Many2one('im_livechat.channel', string='Website Live Chat Channel')
|
|
|
|
@api.multi
|
|
def get_livechat_channel_info(self):
|
|
""" Get the livechat info dict (button text, channel name, ...) for the livechat channel of
|
|
the current website.
|
|
"""
|
|
self.ensure_one()
|
|
if self.channel_id:
|
|
return self.channel_id.sudo().get_livechat_info()
|
|
return {}
|