From 5fdfd38b7e72549c65acd56cd91f388b358f8f4d Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Wed, 2 Dec 2015 09:24:33 +0100 Subject: [PATCH] [FIX] im_livechat: don't remove empty sessions created recently The 'cron_remove_empty_session' is performed every day and removes livechat channels that contain no message. The problem was that the cron might have been executed between the moment a public user clicked on the livechat button, creating a new empty channel, and the moment this user sent the first message through that channel. If that happenned, the message was sent in an unexisting channel, and obviously never received by the operator. This fix makes sure that removed empty channels haven't been created or modified within the last hour. --- addons/im_livechat/models/mail_channel.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/addons/im_livechat/models/mail_channel.py b/addons/im_livechat/models/mail_channel.py index 2119baf38cc..eded0ff17da 100644 --- a/addons/im_livechat/models/mail_channel.py +++ b/addons/im_livechat/models/mail_channel.py @@ -58,6 +58,7 @@ class MailChannel(models.Model): @api.model def cron_remove_empty_session(self): + hours = 1 # never remove empty session created within the last hour self.env.cr.execute(""" SELECT id as id FROM mail_channel C @@ -65,7 +66,8 @@ class MailChannel(models.Model): SELECT * FROM mail_message_mail_channel_rel R WHERE R.mail_channel_id = C.id - ) AND C.channel_type = 'livechat' AND livechat_channel_id IS NOT NULL; - """) + ) AND C.channel_type = 'livechat' AND livechat_channel_id IS NOT NULL AND + COALESCE(write_date, create_date, (now() at time zone 'UTC'))::timestamp + < ((now() at time zone 'UTC') - interval %s)""", ("%s hours" % hours,)) empty_channel_ids = [item['id'] for item in self.env.cr.dictfetchall()] self.browse(empty_channel_ids).unlink()