[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
This commit is contained in:
@@ -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'),
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
<group>
|
||||
<group string="Status">
|
||||
<field name="auto_delete"/>
|
||||
<field name="notification"/>
|
||||
<field name="is_notification"/>
|
||||
<field name="message_type"/>
|
||||
<field name="mail_server_id"/>
|
||||
<field name="model"/>
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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': '<p>Test</p>',
|
||||
'notification': True,
|
||||
'is_notification': True,
|
||||
'state': 'outgoing',
|
||||
'recipient_ids': [(4, self.partner.id)]
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user