diff --git a/addons/im_livechat/im_livechat.py b/addons/im_livechat/im_livechat.py
index d4affe4b971..558668de10d 100644
--- a/addons/im_livechat/im_livechat.py
+++ b/addons/im_livechat/im_livechat.py
@@ -25,7 +25,7 @@ import random
import re
from openerp.osv import osv, fields
-from openerp import tools
+from openerp import api, models, tools
class im_livechat_channel(osv.Model):
@@ -293,3 +293,26 @@ class im_chat_session(osv.Model):
else:
return super(im_chat_session, self).quit_user(cr, uid, session.id, context=context)
+
+ def cron_remove_empty_session(self, cr, uid, context=None):
+ groups = self.pool['im_chat.message'].read_group(cr, uid, [], ['to_id'], ['to_id'], context=context)
+ not_empty_session_ids = [group['to_id'][0] for group in groups]
+ empty_session_ids = self.search(cr, uid, [('id', 'not in', not_empty_session_ids), ('channel_id', '!=', False)], context=context)
+ self.unlink(cr, uid, empty_session_ids, context=context)
+
+
+
+class Rating(models.Model):
+
+ _inherit = "rating.rating"
+
+ @api.one
+ @api.depends('res_model', 'res_id')
+ def _compute_res_name(self):
+ # cannot change the rec_name of session since it is use to create the bus channel
+ # so, need to override this method to set the same alternative rec_name as in reporting
+ if self.res_model == 'im_chat.session':
+ current_object = self.env[self.res_model].sudo().browse(self.res_id)
+ self.res_name = ('%s / %s') % (current_object.channel_id.name, current_object.id)
+ else:
+ super(Rating, self)._compute_res_name()
diff --git a/addons/im_livechat/im_livechat_data.xml b/addons/im_livechat/im_livechat_data.xml
index 2f21a321002..8394d25c16d 100644
--- a/addons/im_livechat/im_livechat_data.xml
+++ b/addons/im_livechat/im_livechat_data.xml
@@ -13,6 +13,19 @@
open
+
+
+
+ [im_livechat] Remove empty anonymous sessions
+ 1
+ days
+ -1
+
+ im_chat.session
+ cron_remove_empty_session
+
+
+
diff --git a/addons/rating/models/rating.py b/addons/rating/models/rating.py
index dab705fc9fa..44d446b4b0c 100644
--- a/addons/rating/models/rating.py
+++ b/addons/rating/models/rating.py
@@ -12,12 +12,11 @@ class Rating(models.Model):
('rating_range', 'check(rating >= -1 and rating <= 10)', 'Rating should be between -1 to 10'),
]
- @api.multi
+ @api.one
@api.depends('res_model', 'res_id')
def _compute_res_name(self):
- for record in self:
- name = self.env[record.res_model].sudo().browse(record.res_id).name_get()
- record.res_name = name and name[0][1] or ('%s/%s') % (record.res_model, record.res_id)
+ name = self.env[self.res_model].sudo().browse(self.res_id).name_get()
+ self.res_name = name and name[0][1] or ('%s/%s') % (self.res_model, self.res_id)
@api.model
def new_access_token(self):