summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Bohy <aab@odoo.com>2015-12-02 09:24:33 +0100
committerAaron Bohy <aab@odoo.com>2015-12-03 11:21:47 +0100
commit5fdfd38b7e72549c65acd56cd91f388b358f8f4d (patch)
tree98f8d5f0ac087e8dd14339bce1f463c2773109c4
parent8017a9569cbd648b3ff205c198efb8c5a9530d7d (diff)
[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.
-rw-r--r--addons/im_livechat/models/mail_channel.py6
1 files 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()