From 19ce266dbf198544d923dc83c1187ee9f4480b67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Wed, 28 Jul 2021 14:41:36 +0000 Subject: [PATCH] [REF] mail: rename notification of mail.mail to is_notification RATIONALE Prepare code cleaning and optimization in mail, mass_mailing and SMS by cleaning models for readability and code complexity and footprint reduction. SPECIFICATIONS Purpose is to prepare future changes by easing its grep. Notification is too much heavily used through the codebase and finding it was quite hard among other noise. Rename ``notification`` field to ``is_notification``. LINKS Task ID-2377974 Community PR odoo/odoo#61467 Enterprise PR odoo/enterprise#14633 Upgrade PR odoo/upgrade#1907 --- addons/mail/models/mail_mail.py | 10 +++++----- addons/mail/views/mail_mail_views.xml | 2 +- addons/mail/wizard/mail_compose_message.py | 4 ++-- addons/mass_mailing/wizard/mail_compose_message.py | 2 +- addons/mass_mailing/wizard/mailing_mailing_test.py | 2 +- addons/test_mail/tests/test_mail_mail.py | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/addons/mail/models/mail_mail.py b/addons/mail/models/mail_mail.py index 1c10d7efd0b..64a56c4403d 100644 --- a/addons/mail/models/mail_mail.py +++ b/addons/mail/models/mail_mail.py @@ -35,7 +35,7 @@ class MailMail(models.Model): headers = fields.Text('Headers', copy=False) # Auto-detected based on create() - if 'mail_message_id' was passed then this mail is a notification # and during unlink() we will not cascade delete the parent and its attachments - notification = fields.Boolean('Is Notification', help='Mail has been created to notify people of an existing mail.message') + is_notification = fields.Boolean('Notification Email', help='Mail has been created to notify people of an existing mail.message') # recipients: include inactive partners (they may have been archived after # the message was sent, but they should remain visible in the relation) email_to = fields.Text('To', help='Message recipients (emails)') @@ -75,8 +75,8 @@ class MailMail(models.Model): def create(self, values_list): # notification field: if not set, set if mail comes from an existing mail.message for values in values_list: - if 'notification' not in values and values.get('mail_message_id'): - values['notification'] = True + if 'is_notification' not in values and values.get('mail_message_id'): + values['is_notification'] = True new_mails = super(MailMail, self).create(values_list) @@ -98,7 +98,7 @@ class MailMail(models.Model): def unlink(self): # cascade-delete the parent message for all mails that are not created for a notification - mail_msg_cascade_ids = [mail.mail_message_id.id for mail in self if not mail.notification] + mail_msg_cascade_ids = [mail.mail_message_id.id for mail in self if not mail.is_notification] res = super(MailMail, self).unlink() if mail_msg_cascade_ids: self.env['mail.message'].browse(mail_msg_cascade_ids).unlink() @@ -168,7 +168,7 @@ class MailMail(models.Model): :return: True """ - notif_mails_ids = [mail.id for mail in self if mail.notification] + notif_mails_ids = [mail.id for mail in self if mail.is_notification] if notif_mails_ids: notifications = self.env['mail.notification'].search([ ('notification_type', '=', 'email'), diff --git a/addons/mail/views/mail_mail_views.xml b/addons/mail/views/mail_mail_views.xml index 420d5522d06..6a6a1121b72 100644 --- a/addons/mail/views/mail_mail_views.xml +++ b/addons/mail/views/mail_mail_views.xml @@ -37,7 +37,7 @@ - + diff --git a/addons/mail/wizard/mail_compose_message.py b/addons/mail/wizard/mail_compose_message.py index 10dcf89aad3..5c7fb382c15 100644 --- a/addons/mail/wizard/mail_compose_message.py +++ b/addons/mail/wizard/mail_compose_message.py @@ -372,7 +372,7 @@ class MailComposer(models.TransientModel): record = self.env[self.model].browse(res_id) mail_values['headers'] = record._notify_email_headers() # keep a copy unless specifically requested, reset record name (avoid browsing records) - mail_values.update(notification=not self.auto_delete_message, model=self.model, res_id=res_id, record_name=False) + mail_values.update(is_notification=not self.auto_delete_message, model=self.model, res_id=res_id, record_name=False) # auto deletion of mail_mail if self.auto_delete or self.template_id.auto_delete: mail_values['auto_delete'] = True @@ -471,7 +471,7 @@ class MailComposer(models.TransientModel): mail_values['state'] = 'cancel' mail_values['failure_type'] = 'mail_bl' # Do not post the mail into the recipient's chatter - mail_values['notification'] = False + mail_values['is_notification'] = False elif optout_emails and mail_to in optout_emails: mail_values['state'] = 'cancel' mail_values['failure_type'] = 'mail_optout' diff --git a/addons/mass_mailing/wizard/mail_compose_message.py b/addons/mass_mailing/wizard/mail_compose_message.py index 3c6c978f2dc..d863ff25dbc 100644 --- a/addons/mass_mailing/wizard/mail_compose_message.py +++ b/addons/mass_mailing/wizard/mail_compose_message.py @@ -65,7 +65,7 @@ class MailComposeMessage(models.TransientModel): 'mailing_id': mass_mailing.id, 'mailing_trace_ids': [(0, 0, trace_vals)], # email-mode: keep original message for routing - 'notification': mass_mailing.reply_to_mode == 'update', + 'is_notification': mass_mailing.reply_to_mode == 'update', 'auto_delete': not mass_mailing.keep_archives, }) return res diff --git a/addons/mass_mailing/wizard/mailing_mailing_test.py b/addons/mass_mailing/wizard/mailing_mailing_test.py index 933b81badbf..88563d44475 100644 --- a/addons/mass_mailing/wizard/mailing_mailing_test.py +++ b/addons/mass_mailing/wizard/mailing_mailing_test.py @@ -56,7 +56,7 @@ class TestMassMailing(models.TransientModel): 'email_to': valid_email, 'subject': subject, 'body_html': mass_mail_layout._render({'body': full_body}, engine='ir.qweb', minimal_qcontext=True), - 'notification': True, + 'is_notification': True, 'mailing_id': mailing.id, 'attachment_ids': [(4, attachment.id) for attachment in mailing.attachment_ids], 'auto_delete': False, # they are manually deleted after notifying the document diff --git a/addons/test_mail/tests/test_mail_mail.py b/addons/test_mail/tests/test_mail_mail.py index 9151d43c488..86ce0a087ca 100644 --- a/addons/test_mail/tests/test_mail_mail.py +++ b/addons/test_mail/tests/test_mail_mail.py @@ -143,7 +143,7 @@ class TestMailMailRace(common.TransactionCase): # we need to simulate a mail sent by the cron task, first create mail, message and notification by hand mail = self.env['mail.mail'].sudo().create({ 'body_html': '

Test

', - 'notification': True, + 'is_notification': True, 'state': 'outgoing', 'recipient_ids': [(4, self.partner.id)] })