diff --git a/addons/im_livechat/report/im_livechat_report_channel.py b/addons/im_livechat/report/im_livechat_report_channel.py index c6314fbc2af..21305ab7b99 100644 --- a/addons/im_livechat/report/im_livechat_report_channel.py +++ b/addons/im_livechat/report/im_livechat_report_channel.py @@ -55,12 +55,14 @@ class ImLivechatReportChannel(models.Model): to_char(date_trunc('hour', C.create_date), 'YYYY-MM-DD HH24:MI:SS') as start_date_hour, to_char(date_trunc('hour', C.create_date), 'HH24') as start_hour, extract(dow from C.create_date) as day_number, - EXTRACT('epoch' FROM (max((SELECT (max(M.create_date)) FROM mail_message M JOIN mail_message_mail_channel_rel R ON (R.mail_message_id = M.id) WHERE R.mail_channel_id = C.id))-C.create_date)) as duration, - EXTRACT('epoch' from ((SELECT min(M.create_date) FROM mail_message M, mail_message_mail_channel_rel R WHERE M.author_id=C.livechat_operator_id AND R.mail_channel_id = C.id AND R.mail_message_id = M.id)-(SELECT min(M.create_date) FROM mail_message M, mail_message_mail_channel_rel R WHERE M.author_id IS NULL AND R.mail_channel_id = C.id AND R.mail_message_id = M.id))) as time_to_answer, + EXTRACT('epoch' FROM MAX(M.create_date) - MIN(M.create_date)) AS duration, + EXTRACT('epoch' FROM MIN(MO.create_date) - MIN(M.create_date)) AS time_to_answer, count(distinct C.livechat_operator_id) as nbr_speaker, count(distinct M.id) as nbr_message, CASE - WHEN EXISTS (select distinct M.author_id FROM mail_message M, mail_message_mail_channel_rel R WHERE M.author_id=C.livechat_operator_id AND R.mail_channel_id = C.id AND R.mail_message_id = M.id and C.livechat_operator_id = M.author_id) + WHEN EXISTS (select distinct M.author_id FROM mail_message M, mail_message_mail_channel_rel R + WHERE M.author_id=C.livechat_operator_id AND R.mail_channel_id = C.id + AND R.mail_message_id = M.id and C.livechat_operator_id = M.author_id) THEN 0 ELSE 1 END as is_without_answer, @@ -87,10 +89,12 @@ class ImLivechatReportChannel(models.Model): END as is_unrated, C.livechat_operator_id as partner_id FROM mail_channel C - JOIN mail_message_mail_channel_rel R ON (C.id = R.mail_channel_id and C.livechat_operator_id is not null) + JOIN mail_message_mail_channel_rel R ON (C.id = R.mail_channel_id) JOIN mail_message M ON (M.id = R.mail_message_id) JOIN im_livechat_channel L ON (L.id = C.livechat_channel_id) + LEFT JOIN mail_message MO ON (R.mail_message_id = MO.id AND MO.author_id = C.livechat_operator_id) LEFT JOIN rating_rating Rate ON (Rate.res_id = C.id and Rate.res_model = 'mail.channel' and Rate.parent_res_model = 'im_livechat.channel') + WHERE C.livechat_operator_id is not null GROUP BY C.livechat_operator_id, C.id, C.name, C.livechat_channel_id, L.name, C.create_date, C.uuid, Rate.rating ) """) diff --git a/addons/im_livechat/report/im_livechat_report_operator.py b/addons/im_livechat/report/im_livechat_report_operator.py index a212cd5633b..a9391e2a6be 100644 --- a/addons/im_livechat/report/im_livechat_report_operator.py +++ b/addons/im_livechat/report/im_livechat_report_operator.py @@ -28,15 +28,18 @@ class ImLivechatReportOperator(models.Model): CREATE OR REPLACE VIEW im_livechat_report_operator AS ( SELECT row_number() OVER () AS id, - C.livechat_operator_id as partner_id, - L.id as livechat_channel_id, - count(C.id) as nbr_channel, - C.id as channel_id, - C.create_date as start_date, - EXTRACT('epoch' FROM (max((SELECT (max(M.create_date)) FROM mail_message M JOIN mail_message_mail_channel_rel R ON (R.mail_message_id = M.id) WHERE R.mail_channel_id = C.id))-C.create_date)) as duration, - EXTRACT('epoch' from ((SELECT min(M.create_date) FROM mail_message M, mail_message_mail_channel_rel R WHERE M.author_id=C.livechat_operator_id AND R.mail_channel_id = C.id AND R.mail_message_id = M.id)-(SELECT min(M.create_date) FROM mail_message M, mail_message_mail_channel_rel R WHERE M.author_id IS NULL AND R.mail_channel_id = C.id AND R.mail_message_id = M.id))) as time_to_answer + C.livechat_operator_id AS partner_id, + C.livechat_channel_id AS livechat_channel_id, + COUNT(DISTINCT C.id) AS nbr_channel, + C.id AS channel_id, + C.create_date AS start_date, + EXTRACT('epoch' FROM MAX(M.create_date) - MIN(M.create_date)) AS duration, + EXTRACT('epoch' FROM MIN(MO.create_date) - MIN(M.create_date)) AS time_to_answer FROM mail_channel C - JOIN im_livechat_channel L ON (L.id = C.livechat_channel_id and C.livechat_operator_id is not null) - GROUP BY C.livechat_operator_id, L.id, C.id, C.create_date + JOIN mail_message_mail_channel_rel R ON R.mail_channel_id = C.id + JOIN mail_message M ON R.mail_message_id = M.id + LEFT JOIN mail_message MO ON (R.mail_message_id = MO.id AND MO.author_id = C.livechat_operator_id) + WHERE C.livechat_channel_id IS NOT NULL + GROUP BY C.id, C.livechat_operator_id ) """)