Files
odoo_source/addons/website_livechat/controllers/main.py
T
David Beguin ce20c29f82 [IMP] website_livechat : show ratings per operators in channel stat webpage
This commit adds more precision about ratings per operators for a
specific channel. Only the operators that have been rated on the last 100
feedbacks have their statistics displayed. The other operators that did not
worked (or have not been rated) on the last 100 feedbacks are still displayed
but are flaged as 'Not rated yet', so we still can see who is working on this
channel.

Task ID : 1895998
Closes PR #28283
2018-12-05 14:37:13 +00:00

58 lines
2.6 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import http
from odoo.http import request
class WebsiteLivechat(http.Controller):
@http.route('/livechat/', type='http', auth="public", website=True)
def channel_list(self, **kw):
# display the list of the channel
channels = request.env['im_livechat.channel'].search([('website_published', '=', True)])
values = {
'channels': channels
}
return request.render('website_livechat.channel_list_page', values)
@http.route('/livechat/channel/<model("im_livechat.channel"):channel>', type='http', auth='public', website=True)
def channel_rating(self, channel, **kw):
# get the last 100 ratings and the repartition per grade
domain = [
('res_model', '=', 'mail.channel'), ('res_id', 'in', channel.sudo().channel_ids.ids),
('consumed', '=', True), ('rating', '>=', 1),
]
ratings = request.env['rating.rating'].search(domain, order='create_date desc', limit=100)
repartition = channel.sudo().channel_ids.rating_get_grades(domain=domain)
# compute percentage
percentage = dict.fromkeys(['great', 'okay', 'bad'], 0)
for grade in repartition:
percentage[grade] = round(repartition[grade] * 100.0 / sum(repartition.values()), 1) if sum(repartition.values()) else 0
# filter only on the team users that worked on the last 100 ratings and get their detailed stat
ratings_per_partner = dict.fromkeys(ratings.mapped('rated_partner_id.id'), dict.fromkeys(['great', 'okay', 'bad'], 0))
total_ratings_per_partner = dict.fromkeys(ratings.mapped('rated_partner_id.id'), 0)
rating_texts = {10: 'great', 5: 'okay', 1: 'bad'}
for rating in ratings:
partner_id = rating.rated_partner_id.id
ratings_per_partner[partner_id][rating_texts[rating.rating]] += 1
total_ratings_per_partner[partner_id] += 1
for partner_id, rating in ratings_per_partner.items():
for k, v in ratings_per_partner[partner_id].items():
ratings_per_partner[partner_id][k] = round(100 * v / total_ratings_per_partner[partner_id], 1)
# the value dict to render the template
values = {
'channel': channel,
'ratings': ratings,
'team': channel.sudo().user_ids,
'percentage': percentage,
'ratings_per_user': ratings_per_partner
}
return request.render("website_livechat.channel_page", values)