From ba9e79f29ca23aaa77f41000b72f445f1527ef91 Mon Sep 17 00:00:00 2001 From: ryv-odoo Date: Thu, 12 Dec 2019 10:08:38 +0000 Subject: [PATCH] [REF] mail: rename mail.notification table MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit RATIONALE A bit of history. Link between a message and its recipients has been added at first mail refactoring towards a Chatter / Discuss feature. It was done in v7 at d64f3c97837f80ff516b3336f5ad388d2fe3b442 with the base addition of mail notification model (lots of commits follow that one but that's the first one about notification). Due to some people thinking that it was unnecessary to keep a model for notification it has been removed in v9 at 88b8cd058713bfad2942f7e7434c34b6c1a6e7da. Notification table was renamed from mail_notification to mail_message_res_partner_needaction_rel. It was proven to be a mistake even if those "some people" were warned and model made its way back to Odoo in v10 at 72dfcae2a4b03623e780b857abf37c7aec5b8456 . Table name mail_message _res_partner_needaction_rel was kept to ease migration and backward compatibility. It is now time to complete the circle and rename it to mail_notification. SPECIFICATIONS Rename ``mail_message_res_partner_needaction_rel`` to ``mail_notification`` . RIP JEM. Never forget. LINKS Task ID-2477444 Prepares Task ID-2377974 (trace management cleaning task) Prepares Task ID-2070632 (channel members main task) Prepares Task ID-2419762 (channel members followup task) COM PR odoo/odoo#67382 UPG PR odoo/upgrade#2245 Co-Authored-By: Rémy Voet Co-Authored-By: Thibault Delavallée --- addons/mail/models/mail_message.py | 8 ++++---- addons/mail/models/mail_notification.py | 4 ++-- addons/mail/models/mail_thread.py | 4 ++-- addons/mail/models/res_partner.py | 2 +- addons/mail/wizard/mail_resend_cancel.py | 2 +- addons/sms/models/mail_thread.py | 2 +- addons/sms/wizard/sms_cancel.py | 2 +- addons/test_mail/tests/test_mail_mail.py | 4 ++-- 8 files changed, 14 insertions(+), 14 deletions(-) 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)