[IMP] mail: add constraint at db level for partner / message notification
Add a constraint directly at db level ensuring no duplicated notification exist on partner / message pair, if partner is set. Partner can be void notably with SMS notification process which may target numbers directly. Task-2710804 (Mail: Clean Mail.Thread API) Part-of: odoo/odoo#82167
This commit is contained in:
@@ -44,7 +44,7 @@ class MailNotification(models.Model):
|
||||
failure_reason = fields.Text('Failure reason', copy=False)
|
||||
|
||||
_sql_constraints = [
|
||||
# email notification;: partner is required
|
||||
# email notification: partner is required
|
||||
('notification_partner_required',
|
||||
"CHECK(notification_type NOT IN ('email', 'inbox') OR res_partner_id IS NOT NULL)",
|
||||
'Customer is required for inbox / email notification'),
|
||||
@@ -59,6 +59,11 @@ class MailNotification(models.Model):
|
||||
CREATE INDEX IF NOT EXISTS mail_notification_res_partner_id_is_read_notification_status_mail_message_id
|
||||
ON mail_notification (res_partner_id, is_read, notification_status, mail_message_id)
|
||||
""")
|
||||
self.env.cr.execute(
|
||||
"""CREATE UNIQUE INDEX IF NOT EXISTS unique_mail_message_id_res_partner_id_if_set
|
||||
ON %s (mail_message_id, res_partner_id)
|
||||
WHERE res_partner_id IS NOT NULL""" % self._table
|
||||
)
|
||||
|
||||
@api.model_create_multi
|
||||
def create(self, vals_list):
|
||||
|
||||
@@ -53,6 +53,7 @@ class TestMessagePost(TestMailCommon, TestRecipients):
|
||||
for email_xmlid in ['mail.message_notification_email',
|
||||
'mail.mail_notification_light',
|
||||
'mail.mail_notification_paynow']:
|
||||
test_message.sudo().notification_ids.unlink() # otherwise partner/message constraint fails
|
||||
test_message.write({'email_layout_xmlid': email_xmlid})
|
||||
with self.mock_mail_gateway():
|
||||
test_record._notify_thread_by_email(
|
||||
|
||||
Reference in New Issue
Block a user