diff options
| author | Jérome Maes <jem@openerp.com> | 2015-03-05 15:22:12 +0100 |
|---|---|---|
| committer | Jérome Maes <jem@openerp.com> | 2015-03-05 16:31:18 +0100 |
| commit | 63e53410817bd2e67c2bf1a2ce5bb969c8ae5666 (patch) | |
| tree | 357045e1ff1d81cd4ec1265465a5f9e43251c110 | |
| parent | 3186d86b8b63d510beaf16f86ef9d5761bd06a72 (diff) | |
[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.
| -rw-r--r-- | addons/im_livechat/im_livechat.py | 25 | ||||
| -rw-r--r-- | addons/im_livechat/im_livechat_data.xml | 13 | ||||
| -rw-r--r-- | addons/rating/models/rating.py | 7 |
3 files changed, 40 insertions, 5 deletions
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 @@ <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> 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): |
