diff --git a/addons/mail/models/mail_message.py b/addons/mail/models/mail_message.py index ca0b8912e38..da31b2c2b76 100644 --- a/addons/mail/models/mail_message.py +++ b/addons/mail/models/mail_message.py @@ -129,7 +129,7 @@ class Message(models.Model): # list of partner having a notification. Caution: list may change over time because of notif gc cron. # mainly usefull for testing notified_partner_ids = fields.Many2many( - 'res.partner', 'mail_message_res_partner_needaction_rel', string='Partners with Need Action', + 'res.partner', 'mail_notification', string='Partners with Need Action', context={'active_test': False}, depends=['notification_ids']) needaction = fields.Boolean( 'Need Action', compute='_get_needaction', search='_search_needaction', @@ -309,7 +309,7 @@ class Message(models.Model): FROM "%s" m LEFT JOIN "mail_message_res_partner_rel" partner_rel ON partner_rel.mail_message_id = m.id AND partner_rel.res_partner_id = %%(pid)s - LEFT JOIN "mail_message_res_partner_needaction_rel" needaction_rel + LEFT JOIN "mail_notification" needaction_rel ON needaction_rel.mail_message_id = m.id AND needaction_rel.res_partner_id = %%(pid)s LEFT JOIN "mail_message_mail_channel_rel" channel_rel ON channel_rel.mail_message_id = m.id @@ -431,7 +431,7 @@ class Message(models.Model): FROM "%s" m LEFT JOIN "mail_message_res_partner_rel" partner_rel ON partner_rel.mail_message_id = m.id AND partner_rel.res_partner_id = %%(pid)s - LEFT JOIN "mail_message_res_partner_needaction_rel" needaction_rel + LEFT JOIN "mail_notification" needaction_rel ON needaction_rel.mail_message_id = m.id AND needaction_rel.res_partner_id = %%(pid)s LEFT JOIN "mail_message_mail_channel_rel" channel_rel ON channel_rel.mail_message_id = m.id @@ -460,7 +460,7 @@ class Message(models.Model): FROM "%s" m LEFT JOIN "mail_message_res_partner_rel" partner_rel ON partner_rel.mail_message_id = m.id AND partner_rel.res_partner_id = %%(pid)s - LEFT JOIN "mail_message_res_partner_needaction_rel" needaction_rel + LEFT JOIN "mail_notification" needaction_rel ON needaction_rel.mail_message_id = m.id AND needaction_rel.res_partner_id = %%(pid)s LEFT JOIN "mail_message_mail_channel_rel" channel_rel ON channel_rel.mail_message_id = m.id diff --git a/addons/mail/models/mail_notification.py b/addons/mail/models/mail_notification.py index 5e87c6ac990..51db4cbfc7b 100644 --- a/addons/mail/models/mail_notification.py +++ b/addons/mail/models/mail_notification.py @@ -10,7 +10,7 @@ from odoo.tools.translate import _ class MailNotification(models.Model): _name = 'mail.notification' - _table = 'mail_message_res_partner_needaction_rel' + _table = 'mail_notification' _rec_name = 'res_partner_id' _log_access = False _description = 'Message Notifications' @@ -54,7 +54,7 @@ class MailNotification(models.Model): if not self._cr.fetchone(): self._cr.execute(""" CREATE INDEX mail_notification_res_partner_id_is_read_notification_status_mail_message_id - ON mail_message_res_partner_needaction_rel (res_partner_id, is_read, notification_status, mail_message_id) + ON mail_notification (res_partner_id, is_read, notification_status, mail_message_id) """) @api.model_create_multi diff --git a/addons/mail/models/mail_thread.py b/addons/mail/models/mail_thread.py index 1dc1a8d2de0..66168e7ffb5 100644 --- a/addons/mail/models/mail_thread.py +++ b/addons/mail/models/mail_thread.py @@ -201,7 +201,7 @@ class MailThread(models.AbstractModel): if self.ids: # search for unread messages, directly in SQL to improve performances self._cr.execute(""" SELECT msg.res_id FROM mail_message msg - RIGHT JOIN mail_message_res_partner_needaction_rel rel + RIGHT JOIN mail_notification rel ON rel.mail_message_id = msg.id AND rel.res_partner_id = %s AND (rel.is_read = false OR rel.is_read IS NULL) WHERE msg.model = %s AND msg.res_id in %s AND msg.message_type != 'user_notification'""", (self.env.user.partner_id.id, self._name, tuple(self.ids),)) @@ -220,7 +220,7 @@ class MailThread(models.AbstractModel): res = {} if self.ids: self._cr.execute(""" SELECT msg.res_id, COUNT(msg.res_id) FROM mail_message msg - RIGHT JOIN mail_message_res_partner_needaction_rel rel + RIGHT JOIN mail_notification rel ON rel.mail_message_id = msg.id AND rel.notification_status in ('exception','bounce') WHERE msg.author_id = %s AND msg.model = %s AND msg.res_id in %s AND msg.message_type != 'user_notification' GROUP BY msg.res_id""", diff --git a/addons/mail/models/res_partner.py b/addons/mail/models/res_partner.py index cdacd081db5..2167c2d5354 100644 --- a/addons/mail/models/res_partner.py +++ b/addons/mail/models/res_partner.py @@ -86,7 +86,7 @@ class Partner(models.Model): self.env['mail.notification'].flush(['is_read', 'res_partner_id']) self.env.cr.execute(""" SELECT count(*) as needaction_count - FROM mail_message_res_partner_needaction_rel R + FROM mail_notification R WHERE R.res_partner_id = %s AND (R.is_read = false OR R.is_read IS NULL)""", (self.env.user.partner_id.id,)) return self.env.cr.dictfetchall()[0].get('needaction_count') _logger.error('Call to needaction_count without partner_id') diff --git a/addons/mail/wizard/mail_resend_cancel.py b/addons/mail/wizard/mail_resend_cancel.py index dfeef29625c..ee919e2d7b1 100644 --- a/addons/mail/wizard/mail_resend_cancel.py +++ b/addons/mail/wizard/mail_resend_cancel.py @@ -21,7 +21,7 @@ class MailResendCancel(models.TransientModel): for wizard in self: self._cr.execute(""" SELECT notif.id, mes.id - FROM mail_message_res_partner_needaction_rel notif + FROM mail_notification notif JOIN mail_message mes ON notif.mail_message_id = mes.id WHERE notif.notification_type = 'email' AND notif.notification_status IN ('bounce', 'exception') diff --git a/addons/sms/models/mail_thread.py b/addons/sms/models/mail_thread.py index c3ff8168faa..bda92a5a87b 100644 --- a/addons/sms/models/mail_thread.py +++ b/addons/sms/models/mail_thread.py @@ -21,7 +21,7 @@ class MailThread(models.AbstractModel): res = {} if self.ids: self._cr.execute(""" SELECT msg.res_id, COUNT(msg.res_id) FROM mail_message msg - RIGHT JOIN mail_message_res_partner_needaction_rel rel + RIGHT JOIN mail_notification rel ON rel.mail_message_id = msg.id AND rel.notification_type = 'sms' AND rel.notification_status in ('exception') WHERE msg.author_id = %s AND msg.model = %s AND msg.res_id in %s AND msg.message_type != 'user_notification' GROUP BY msg.res_id""", diff --git a/addons/sms/wizard/sms_cancel.py b/addons/sms/wizard/sms_cancel.py index 0587a9f039c..ab75c2c6873 100644 --- a/addons/sms/wizard/sms_cancel.py +++ b/addons/sms/wizard/sms_cancel.py @@ -22,7 +22,7 @@ class SMSCancel(models.TransientModel): for wizard in self: self._cr.execute(""" SELECT notif.id, msg.id -FROM mail_message_res_partner_needaction_rel notif +FROM mail_notification notif JOIN mail_message msg ON notif.mail_message_id = msg.id WHERE notif.notification_type = 'sms' IS TRUE AND notif.notification_status IN ('bounce', 'exception') diff --git a/addons/test_mail/tests/test_mail_mail.py b/addons/test_mail/tests/test_mail_mail.py index 9af710c910a..740a1c7f61c 100644 --- a/addons/test_mail/tests/test_mail_mail.py +++ b/addons/test_mail/tests/test_mail_mail.py @@ -64,7 +64,7 @@ class TestMailMailRace(common.TransactionCase): with this.registry.cursor() as cr, mute_logger('odoo.sql_db'): try: # try ro aquire lock (no wait) on notification (should fail) - cr.execute("SELECT notification_status FROM mail_message_res_partner_needaction_rel WHERE id = %s FOR UPDATE NOWAIT", [notif.id]) + cr.execute("SELECT notification_status FROM mail_notification WHERE id = %s FOR UPDATE NOWAIT", [notif.id]) except psycopg2.OperationalError: # record already locked by send, all good bounce_deferred.append(True) @@ -73,7 +73,7 @@ class TestMailMailRace(common.TransactionCase): # Only here to simulate the initial use case # If the record is lock, this line would create a deadlock since we are in the same thread # In practice, the update will wait the end of the send() transaction and set the notif as bounce, as expeced - cr.execute("UPDATE mail_message_res_partner_needaction_rel SET notification_status='bounce' WHERE id = %s", [notif.id]) + cr.execute("UPDATE mail_notification SET notification_status='bounce' WHERE id = %s", [notif.id]) return message['Message-Id'] self.env['ir.mail_server']._patch_method('send_email', send_email)