[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.
This commit is contained in:
Aaron Bohy
2015-12-03 11:21:47 +01:00
parent 7bea8412c5
commit 8017a9569c
+2 -2
View File
@@ -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")