[REF] mail: rename mail.notification table

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 d64f3c9783 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 88b8cd0587. 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 72dfcae2a4 . 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 <ryv@odoo.com>
Co-Authored-By: Thibault Delavallée <tde@odoo.com>
This commit is contained in:
ryv-odoo
2021-03-05 15:20:53 +00:00
committed by Thibault Delavallée
co-authored by Thibault Delavallée
parent d2079b1fca
commit ba9e79f29c
8 changed files with 14 additions and 14 deletions
+4 -4
View File
@@ -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
+2 -2
View File
@@ -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
+2 -2
View File
@@ -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""",
+1 -1
View File
@@ -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')
+1 -1
View File
@@ -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')
+1 -1
View File
@@ -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""",
+1 -1
View File
@@ -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')
+2 -2
View File
@@ -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)