[FIX] im_livechat, rating : add a cron in im_livechat to delete empty anonymous sessions. And change the res_name of a rating record for im_chat.session : keep the same notation as in reporting instead of uuid.

This commit is contained in:
Jérome Maes
2015-03-05 16:31:18 +01:00
parent 3186d86b8b
commit 63e5341081
3 changed files with 40 additions and 5 deletions
+24 -1
View File
@@ -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()
+13
View File
@@ -13,6 +13,19 @@
<field name="action_id" ref="action_client_livechat_menu"/>
<field name="state">open</field>
</record>
<!-- Remove automatically the empty anonoymous sessions -->
<record id="ir_cron_remove_empty_session" model="ir.cron">
<field name="name">[im_livechat] Remove empty anonymous sessions</field>
<field name="interval_number">1</field>
<field name="interval_type">days</field>
<field name="numbercall">-1</field>
<field name="doall" eval="False"/>
<field name="model">im_chat.session</field>
<field name="function">cron_remove_empty_session</field>
<field name="active" eval="True"/>
</record>
</data>
<data>
+3 -4
View File
@@ -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):