summaryrefslogtreecommitdiff
path: root/addons/im_livechat/report
diff options
context:
space:
mode:
authorJérome Maes <jem@openerp.com>2015-08-10 16:23:44 +0200
committerAaron Bohy <aab@odoo.com>2015-09-01 20:16:09 +0200
commit95b97d1010e2596c8dbe719382c77c6009819afa (patch)
tree2a5d3b0400785eab023ec1c7768829482682cf24 /addons/im_livechat/report
parent1d54858cbdd10dd6fbfbb3edc1e032317e2ba3f6 (diff)
[REF] im_livechat : refactoring, make it compatbile with the nw mail module, change reporting sql view (split them in 2), adapt view, ...
Diffstat (limited to 'addons/im_livechat/report')
-rw-r--r--addons/im_livechat/report/__init__.py3
-rw-r--r--addons/im_livechat/report/im_livechat_report_channel.py70
-rw-r--r--addons/im_livechat/report/im_livechat_report_channel_views.xml55
-rw-r--r--addons/im_livechat/report/im_livechat_report_operator.py42
-rw-r--r--addons/im_livechat/report/im_livechat_report_operator_views.xml66
5 files changed, 174 insertions, 62 deletions
diff --git a/addons/im_livechat/report/__init__.py b/addons/im_livechat/report/__init__.py
index edfc5d9deeb..02fe2345c7c 100644
--- a/addons/im_livechat/report/__init__.py
+++ b/addons/im_livechat/report/__init__.py
@@ -1,2 +1,3 @@
# -*- coding: utf-8 -*-
-import im_livechat_report
+import im_livechat_report_channel
+import im_livechat_report_operator
diff --git a/addons/im_livechat/report/im_livechat_report_channel.py b/addons/im_livechat/report/im_livechat_report_channel.py
index 4fa0436b001..5e5c012753e 100644
--- a/addons/im_livechat/report/im_livechat_report_channel.py
+++ b/addons/im_livechat/report/im_livechat_report_channel.py
@@ -1,55 +1,51 @@
# -*- coding: utf-8 -*-
-from openerp import api, fields, models, tools
+from openerp import fields, models, tools
-class im_livechat_report(models.Model):
- """ Livechat Support Report """
+class ImLivechatReportChannel(models.Model):
+ """ Livechat Support Report on the Channels """
- _name = "im_livechat.report"
+ _name = "im_livechat.report.channel"
_description = "Livechat Support Report"
- _order = 'start_date, session_name'
+ _order = 'start_date, technical_name'
_auto = False
- session_name = fields.Char('Session Name', readonly=True)
uuid = fields.Char('UUID', readonly=True)
+ channel_id = fields.Many2one('mail.channel', 'Conversation', readonly=True)
+ channel_name = fields.Char('Channel Name', readonly=True)
+ technical_name = fields.Char('Code', readonly=True)
+ livechat_channel_id = fields.Many2one('im_livechat.channel', 'Channel', readonly=True)
start_date = fields.Datetime('Start Date of session', readonly=True, help="Start date of the conversation")
start_date_hour = fields.Char('Hour of start Date of session', readonly=True)
duration = fields.Float('Average duration', digits=(16, 2), readonly=True, group_operator="avg", help="Duration of the conversation (in seconds)")
- time_in_session = fields.Float('Time in session', digits=(16, 2), readonly=True, group_operator="avg", help="Average time the user spend in the conversation")
- time_to_answer = fields.Float('Time to answer', digits=(16, 2), readonly=True, group_operator="avg", help="Average time to give the first answer to the visitor")
- nbr_messages = fields.Integer('Average message', readonly=True, group_operator="avg", help="Number of message in the conversation")
- nbr_user_messages = fields.Integer('Average of messages/user', readonly=True, group_operator="avg", help="Average number of message per user")
- nbr_speakers = fields.Integer('# of speakers', readonly=True, group_operator="avg", help="Number of different speakers")
- user_id = fields.Many2one('res.users', 'User', readonly=True)
- session_id = fields.Many2one('im_chat.session', 'Session', readonly=True)
- channel_id = fields.Many2one('im_livechat.channel', 'Channel', readonly=True)
-
+ nbr_speaker = fields.Integer('# of speakers', readonly=True, group_operator="avg", help="Number of different speakers")
+ nbr_message = fields.Integer('Average message', readonly=True, group_operator="avg", help="Number of message in the conversation")
+ partner_id = fields.Many2one('res.partner', 'Opertor', readonly=True)
def init(self, cr):
# Note : start_date_hour must be remove when the read_group will allow grouping on the hour of a datetime. Don't forget to change the view !
- tools.drop_view_if_exists(cr, 'im_livechat_report')
+ tools.drop_view_if_exists(cr, 'im_livechat_report_channel')
cr.execute("""
- CREATE OR REPLACE VIEW im_livechat_report AS (
+ CREATE OR REPLACE VIEW im_livechat_report_channel AS (
SELECT
- min(M.id) as id,
- S.uuid as uuid,
- CONCAT(C.name, ' / ', S.id) as session_name,
- S.create_date as start_date,
- to_char(date_trunc('hour', S.create_date), 'YYYY-MM-DD HH24:MI:SS') as start_date_hour,
- EXTRACT('epoch' from ((SELECT (max(create_date)-min(create_date)) FROM im_chat_message WHERE to_id=S.id AND from_id = U.id))) as time_in_session,
- EXTRACT('epoch' from ((SELECT min(create_date) FROM im_chat_message WHERE to_id=S.id AND from_id IS NOT NULL)-(SELECT min(create_date) FROM im_chat_message WHERE to_id=S.id AND from_id IS NULL))) as time_to_answer,
- EXTRACT('epoch' from (max((SELECT (max(create_date)) FROM im_chat_message WHERE to_id=S.id))-S.create_date)) as duration,
- (SELECT count(distinct COALESCE(from_id, 0)) FROM im_chat_message WHERE to_id=S.id) as nbr_speakers,
- (SELECT count(id) FROM im_chat_message WHERE to_id=S.id) as nbr_messages,
- count(M.id) as nbr_user_messages,
- U.id as user_id,
- S.channel_id as channel_id,
- S.id as session_id
- FROM im_chat_message M
- LEFT JOIN im_chat_session S on (S.id = M.to_id)
- LEFT JOIN res_users U on (U.id = M.from_id)
- LEFT JOIN im_livechat_channel C on (S.channel_id = C.id)
- WHERE S.channel_id IS NOT NULL
- GROUP BY U.id, M.to_id, S.id, C.name, S.uuid
+ C.id as id,
+ C.uuid as uuid,
+ C.id as channel_id,
+ C.name as channel_name,
+ CONCAT(L.name, ' / ', C.id) as technical_name,
+ C.livechat_channel_id as livechat_channel_id,
+ C.create_date as start_date,
+ to_char(date_trunc('hour', C.create_date), 'YYYY-MM-DD HH24:MI:SS') as start_date_hour,
+ 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,
+ count(distinct P.id) as nbr_speaker,
+ count(distinct M.id) as nbr_message,
+ MAX(S.partner_id) as partner_id
+ FROM mail_channel C
+ 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 mail_channel_partner S ON (S.channel_id = C.id)
+ JOIN im_livechat_channel L ON (L.id = C.livechat_channel_id)
+ LEFT JOIN res_partner P ON (M.author_id = P.id)
+ GROUP BY C.id, C.name, C.livechat_channel_id, L.name, C.create_date, C.uuid
)
""")
diff --git a/addons/im_livechat/report/im_livechat_report_channel_views.xml b/addons/im_livechat/report/im_livechat_report_channel_views.xml
index 65ad87120dd..d8d9ed7dcfa 100644
--- a/addons/im_livechat/report/im_livechat_report_channel_views.xml
+++ b/addons/im_livechat/report/im_livechat_report_channel_views.xml
@@ -2,42 +2,42 @@
<odoo>
<data>
- <record id="im_livechat_report_view_pivot" model="ir.ui.view">
- <field name="name">im_livechat.report.pivot</field>
- <field name="model">im_livechat.report</field>
+ <record id="im_livechat_report_channel_view_pivot" model="ir.ui.view">
+ <field name="name">im_livechat.report.channel.pivot</field>
+ <field name="model">im_livechat.report.channel</field>
<field name="arch" type="xml">
<pivot string="Livechat Support Statistics" disable_linking="True">
- <field name="session_name" type="row"/>
+ <field name="technical_name" type="row"/>
<field name="duration" type="measure"/>
- <field name="nbr_messages" type="measure"/>
- <field name="time_to_answer" type="measure"/>
+ <field name="nbr_message" type="measure"/>
</pivot>
</field>
</record>
- <record id="im_livechat_report_view_graph" model="ir.ui.view">
- <field name="name">im_livechat.report.graph</field>
- <field name="model">im_livechat.report</field>
+ <record id="im_livechat_report_channel_view_graph" model="ir.ui.view">
+ <field name="name">im_livechat.report.channel.graph</field>
+ <field name="model">im_livechat.report.channel</field>
<field name="arch" type="xml">
<graph string="Livechat Support Statistics">
- <field name="session_name"/>
- <field name="nbr_messages" type="measure"/>
+ <field name="technical_name"/>
+ <field name="nbr_message" type="measure"/>
</graph>
</field>
</record>
- <record id="im_livechat_report_view_search" model="ir.ui.view">
- <field name="name">im_livechat.report.search</field>
- <field name="model">im_livechat.report</field>
+ <record id="im_livechat_report_channel_view_search" model="ir.ui.view">
+ <field name="name">im_livechat.report.channel.search</field>
+ <field name="model">im_livechat.report.channel</field>
<field name="arch" type="xml">
<search string="Search report">
- <filter name="missed_session" string="Missed sessions" domain="[('nbr_speakers','&lt;=', 1)]"/>
- <filter name="treated_session" string="Treated sessions" domain="[('nbr_speakers','&gt;', 1)]"/>
+ <filter name="missed_session" string="Missed sessions" domain="[('nbr_speaker','&lt;=', 1)]"/>
+ <filter name="treated_session" string="Treated sessions" domain="[('nbr_speaker','&gt;', 1)]"/>
<filter name="last_24h" string="Last 24h" domain="[('start_date','&gt;', (context_today() - datetime.timedelta(days=1)).strftime('%%Y-%%m-%%d') )]"/>
+ <filter name="last_week" string="Last Week" domain="[('start_date','&gt;', (context_today() - datetime.timedelta(weeks=1)).strftime('%%Y-%%m-%%d') )]"/>
<group expand="0" string="Group By...">
<filter name="group_by_session" string="Session" domain="[]" context="{'group_by':'session_name'}"/>
<filter name="group_by_channel" string="Channel" domain="[]" context="{'group_by':'channel_id'}"/>
- <filter name="group_by_user" string="Operator" domain="[('user_id','!=', False)]" context="{'group_by':'user_id'}"/>
+ <filter name="group_by_operator" string="Operator" domain="[('partner_id','!=', False)]" context="{'group_by':'partner_id'}"/>
<separator orientation="vertical" />
<filter name="group_by_hour" string="Creation date (hour)" domain="[]" context="{'group_by':'start_date_hour'}"/>
<filter name="group_by_day" string="Creation date (day)" domain="[]" context="{'group_by':'start_date:day'}"/>
@@ -49,22 +49,29 @@
</field>
</record>
- <record id="im_livechat_report_action" model="ir.actions.act_window">
- <field name="name">Livechat Support Report</field>
- <field name="res_model">im_livechat.report</field>
+ <record id="im_livechat_report_channel_action" model="ir.actions.act_window">
+ <field name="name">Livechat Support Report Channel</field>
+ <field name="res_model">im_livechat.report.channel</field>
<field name="view_type">form</field>
<field name="view_mode">pivot,graph</field>
- <field name="help">Livechat Support Analysis allows you to easily check and analyse your company livechat session performance. Extract informations about the missed sessions, the audiance, the duration of a session, etc.</field>
+ <field name="context">{"search_default_last_week":1}</field>
+ <field name="help">Livechat Support Channel Statistics allows you to easily check and analyse your company livechat session performance. Extract informations about the missed sessions, the audiance, the duration of a session, etc.</field>
</record>
-
<menuitem
id="menu_reporting_livechat"
name="Report"
parent="menu_livechat_root"
sequence="50"
- groups="im_livechat_group_manager"
- action="im_livechat_report_action"/>
+ groups="im_livechat_group_manager"/>
+
+ <menuitem
+ id="menu_reporting_livechat_channel"
+ name="Session Statistics"
+ parent="menu_reporting_livechat"
+ sequence="10"
+ action="im_livechat_report_channel_action"/>
+
</data>
</odoo>
diff --git a/addons/im_livechat/report/im_livechat_report_operator.py b/addons/im_livechat/report/im_livechat_report_operator.py
new file mode 100644
index 00000000000..7a15c90ef11
--- /dev/null
+++ b/addons/im_livechat/report/im_livechat_report_operator.py
@@ -0,0 +1,42 @@
+# -*- coding: utf-8 -*-
+from openerp import fields, models, tools
+
+
+class ImLivechatReportOperator(models.Model):
+ """ Livechat Support Report on the Operator """
+
+ _name = "im_livechat.report.operator"
+ _description = "Livechat Support Report"
+ _order = 'livechat_channel_id, partner_id'
+ _auto = False
+
+ partner_id = fields.Many2one('res.partner', 'Operator', readonly=True)
+ livechat_channel_id = fields.Many2one('im_livechat.channel', 'Channel', readonly=True)
+ nbr_channel = fields.Integer('# of channel', readonly=True, group_operator="sum", help="Number of conversation")
+ channel_id = fields.Many2one('mail.channel', 'Conversation', readonly=True)
+ start_date = fields.Datetime('Start Date of session', readonly=True, help="Start date of the conversation")
+ time_to_answer = fields.Float('Time to answer', digits=(16, 2), readonly=True, group_operator="avg", help="Average time to give the first answer to the visitor")
+ duration = fields.Float('Average duration', digits=(16, 2), readonly=True, group_operator="avg", help="Duration of the conversation (in seconds)")
+
+ def init(self, cr):
+ # Note : start_date_hour must be remove when the read_group will allow grouping on the hour of a datetime. Don't forget to change the view !
+ tools.drop_view_if_exists(cr, 'im_livechat_report_operator')
+ cr.execute("""
+ CREATE OR REPLACE VIEW im_livechat_report_operator AS (
+ SELECT
+ row_number() OVER () AS id,
+ P.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=P.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
+ FROM im_livechat_channel_im_user O
+ JOIN res_users U ON (O.user_id = U.id)
+ JOIN res_partner P ON (U.partner_id = P.id)
+ LEFT JOIN im_livechat_channel L ON (L.id = O.channel_id)
+ LEFT JOIN mail_channel C ON (C.livechat_channel_id = L.id)
+ GROUP BY P.id, L.id, C.id, C.create_date
+ )
+ """)
diff --git a/addons/im_livechat/report/im_livechat_report_operator_views.xml b/addons/im_livechat/report/im_livechat_report_operator_views.xml
new file mode 100644
index 00000000000..902a16ab1ac
--- /dev/null
+++ b/addons/im_livechat/report/im_livechat_report_operator_views.xml
@@ -0,0 +1,66 @@
+<?xml version="1.0"?>
+<odoo>
+ <data>
+
+ <record id="im_livechat_report_operator_view_pivot" model="ir.ui.view">
+ <field name="name">im_livechat.report.operator.pivot</field>
+ <field name="model">im_livechat.report.operator</field>
+ <field name="arch" type="xml">
+ <pivot string="Livechat Support Statistics" disable_linking="True">
+ <field name="partner_id" type="row"/>
+ <field name="duration" type="measure"/>
+ <field name="nbr_channel" type="measure"/>
+ </pivot>
+ </field>
+ </record>
+
+ <record id="im_livechat_report_operator_view_graph" model="ir.ui.view">
+ <field name="name">im_livechat.report.operator.graph</field>
+ <field name="model">im_livechat.report.operator</field>
+ <field name="arch" type="xml">
+ <graph string="Livechat Support Statistics">
+ <field name="partner_id"/>
+ <field name="nbr_channel" type="measure"/>
+ </graph>
+ </field>
+ </record>
+
+ <record id="im_livechat_report_operator_view_search" model="ir.ui.view">
+ <field name="name">im_livechat.report.operator.search</field>
+ <field name="model">im_livechat.report.operator</field>
+ <field name="arch" type="xml">
+ <search string="Search report">
+ <filter name="last_24h" string="Last 24h" domain="[('start_date','&gt;', (context_today() - datetime.timedelta(days=1)).strftime('%%Y-%%m-%%d') )]"/>
+ <filter name="last_week" string="Last Week" domain="[('start_date','&gt;', (context_today() - datetime.timedelta(weeks=1)).strftime('%%Y-%%m-%%d') )]"/>
+ <group expand="0" string="Group By...">
+ <filter name="group_by_channel" string="Channel" domain="[]" context="{'group_by':'channel_id'}"/>
+ <filter name="group_by_operator" string="Operator" domain="[('partner_id','!=', False)]" context="{'group_by':'partner_id'}"/>
+ <separator orientation="vertical" />
+ <filter name="group_by_hour" string="Creation date (hour)" domain="[]" context="{'group_by':'start_date_hour'}"/>
+ <filter name="group_by_day" string="Creation date (day)" domain="[]" context="{'group_by':'start_date:day'}"/>
+ <filter name="group_by_week" string="Creation date (week)" domain="[]" context="{'group_by':'start_date:week'}"/>
+ <filter name="group_by_month" string="Creation date (month)" domain="[]" context="{'group_by':'start_date:month'}" />
+ <filter name="group_by_year" string="Creation date (year)" domain="[]" context="{'group_by':'start_date:year'}"/>
+ </group>
+ </search>
+ </field>
+ </record>
+
+ <record id="im_livechat_report_operator_action" model="ir.actions.act_window">
+ <field name="name">Livechat Support Report Channel</field>
+ <field name="res_model">im_livechat.report.operator</field>
+ <field name="view_type">form</field>
+ <field name="view_mode">pivot,graph</field>
+ <field name="context">{"search_default_last_week":1}</field>
+ <field name="help">Livechat Support Channel Statistics allows you to easily check and analyse your company livechat session performance. Extract informations about the missed sessions, the audiance, the duration of a session, etc.</field>
+ </record>
+
+ <menuitem
+ id="menu_reporting_livechat_operator"
+ name="Operator Analysis"
+ parent="menu_reporting_livechat"
+ sequence="10"
+ action="im_livechat_report_operator_action"/>
+
+ </data>
+</odoo>