From 8017a9569cbd648b3ff205c198efb8c5a9530d7d Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Wed, 2 Dec 2015 09:16:16 +0100 Subject: [PATCH] [FIX] mail: ondelete cascade on mail_channel_partner relation The problem occurred when the im_livechat cron 'cron_remove_empty_session' removed empty livechat channels (a public user clicked on the livechat button, creating a new channel, but never sent any message in it). The empty channel was deleted by the cron, but the two records in the mail_channel_partner relation table (linking the channel with the public user and the livechat operator) wasn't removed, and the value of their field 'channel_id' was None. When this happenned, it broke the SQL query of 'channel_search_to_join()', the RPC call performed when clicking on '+' new to public channels in the client action, resulting in no result displayed in the dropdown. With this fix, records in the relation table are automatically deleted when their corresponding channel or partner is deleted. --- addons/mail/models/mail_channel.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/mail/models/mail_channel.py b/addons/mail/models/mail_channel.py index a2f257a45ca..b72f4c557b4 100644 --- a/addons/mail/models/mail_channel.py +++ b/addons/mail/models/mail_channel.py @@ -18,8 +18,8 @@ class ChannelPartner(models.Model): _table = 'mail_channel_partner' _rec_name = 'partner_id' - partner_id = fields.Many2one('res.partner', string='Recipient') - channel_id = fields.Many2one('mail.channel', string='Channel') + partner_id = fields.Many2one('res.partner', string='Recipient', ondelete='cascade') + channel_id = fields.Many2one('mail.channel', string='Channel', ondelete='cascade') seen_message_id = fields.Many2one('mail.message', string='Last Seen') fold_state = fields.Selection([('open', 'Open'), ('folded', 'Folded'), ('closed', 'Closed')], string='Conversation Fold State', default='open') is_minimized = fields.Boolean("Conversation is minimied")