[IMP] im_livechat: unpin old sessions in the autovacuum cron

This commit is contained in:
Aaron Bohy
2016-06-24 16:34:00 +02:00
parent 7d64bd5ed2
commit 97a8ff9909
2 changed files with 20 additions and 1 deletions
@@ -10,4 +10,5 @@ class AutoVacuum(models.AbstractModel):
@api.model
def power_on(self, *args, **kwargs):
self.pool['mail.channel'].remove_empty_livechat_sessions()
self.pool['mail.channel.partner'].unpin_old_livechat_sessions()
return super(AutoVacuum, self).power_on(*args, **kwargs)
+19 -1
View File
@@ -1,6 +1,24 @@
# -*- coding: utf-8 -*-
from openerp import api, fields, models
from openerp import SUPERUSER_ID
class ChannelPartner(models.Model):
_inherit = 'mail.channel.partner'
@api.model
def unpin_old_livechat_sessions(self):
""" Unpin livechat sessions with no activity for at least one day to
clean the operator's interface """
self.env.cr.execute("""
UPDATE mail_channel_partner
SET is_pinned = false
WHERE id in (
SELECT cp.id FROM mail_channel_partner cp
INNER JOIN mail_channel c on c.id = cp.channel_id
WHERE c.channel_type = 'livechat' AND cp.is_pinned is true AND
cp.write_date < current_timestamp - interval '1 day'
)
""")
class MailChannel(models.Model):