From 2aa7399d0c983046773721b7a2a0b60989ce7dbf Mon Sep 17 00:00:00 2001 From: jem-odoo Date: Thu, 25 Oct 2018 14:13:08 +0000 Subject: [PATCH] [IMP] im_livechat: make channel use rating parent mixin No functionnal changes are done in this commit. Even the period of rating to take into account to compute livechat channel satisfaction (introduced at 5b60e05ce4ed0531a219517855247757841786af) stays the same, but use the parent mixin mecanism. Task-1903565 --- .../im_livechat/models/im_livechat_channel.py | 22 +++---------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/addons/im_livechat/models/im_livechat_channel.py b/addons/im_livechat/models/im_livechat_channel.py index f5547e8cd66..8ff9f864ac3 100644 --- a/addons/im_livechat/models/im_livechat_channel.py +++ b/addons/im_livechat/models/im_livechat_channel.py @@ -3,10 +3,10 @@ import base64 import random import re -from datetime import datetime, timedelta from odoo import api, fields, models, modules, tools + class ImLivechatChannel(models.Model): """ Livechat Channel Define a communication channel, which can be accessed with 'script_external' (script tag to put on @@ -15,7 +15,9 @@ class ImLivechatChannel(models.Model): """ _name = 'im_livechat.channel' + _inherit = ['rating.parent.mixin'] _description = 'Livechat Channel' + _rating_satisfaction_days = 7 # include only last 7 days to compute satisfaction def _default_image(self): image_path = modules.get_module_resource('im_livechat', 'static/src/img', 'default.png') @@ -39,9 +41,6 @@ class ImLivechatChannel(models.Model): compute='_are_you_inside', store=False, readonly=True) script_external = fields.Text('Script (external)', compute='_compute_script_external', store=False, readonly=True) nbr_channel = fields.Integer('Number of conversation', compute='_compute_nbr_channel', store=False, readonly=True) - rating_percentage_satisfaction = fields.Integer( - '% Happy', compute='_compute_percentage_satisfaction', store=False, default=-1, - help="Percentage of happy ratings over the past 7 days") # images fields image = fields.Binary('Image', default=_default_image, attachment=True, @@ -60,7 +59,6 @@ class ImLivechatChannel(models.Model): channel_ids = fields.One2many('mail.channel', 'livechat_channel_id', 'Sessions') rule_ids = fields.One2many('im_livechat.channel.rule', 'channel_id', 'Rules') - @api.one def _are_you_inside(self): self.are_you_inside = bool(self.env.uid in [u.id for u in self.user_ids]) @@ -88,19 +86,6 @@ class ImLivechatChannel(models.Model): for record in self: record.nbr_channel = len(record.channel_ids) - @api.multi - @api.depends('channel_ids.rating_ids') - def _compute_percentage_satisfaction(self): - for record in self: - dt = fields.Datetime.to_string(datetime.utcnow() - timedelta(days=7)) - repartition = record.channel_ids.rating_get_grades([('create_date', '>=', dt)]) - total = sum(repartition.values()) - if total > 0: - happy = repartition['great'] - record.rating_percentage_satisfaction = ((happy*100) / total) if happy > 0 else 0 - else: - record.rating_percentage_satisfaction = -1 - @api.model def create(self, vals): tools.image_resize_images(vals) @@ -211,7 +196,6 @@ class ImLivechatChannelRule(models.Model): _description = 'Livechat Channel Rules' _order = 'sequence asc' - regex_url = fields.Char('URL Regex', help="Regular expression specifying the web pages this rule will be applied on.") action = fields.Selection([('display_button', 'Display the button'), ('auto_popup', 'Auto popup'), ('hide_button', 'Hide the button')],