[REF] mail, sms: simplify notification recipients structure

Now that recipients in notification process are always partners due to
simplification of MailFollower model we can safely simplify the structure
used to collect and propagate recipients information.

Before this task it was a dictionary with a list of partner related data and
a list of channel related data. It is now simply a list of partner related
data, leading to various code cleaning.

LINKS

Task ID-2070632 (main task)
Task ID-2419762 (followup task)
COM PR odoo/odoo#62859
ENT PR odoo/enterprise#15172
UPG PR odoo/upgrade#2005
This commit is contained in:
Thibault Delavallée
2021-03-17 18:22:20 +00:00
parent d08e3676ea
commit c4dacc24fa
7 changed files with 19 additions and 21 deletions
+3 -3
View File
@@ -465,10 +465,10 @@ class Channel(models.Model):
# notify only user input (comment or incoming emails)
if message_type not in ('comment', 'email'):
return {'partners': [], 'channels': []}
return []
# notify only mailing lists or if mentioning recipients
if not mailing_channels and not pids:
return {'partners': [], 'channels': []}
return []
email_from = tools.email_normalize(msg_vals.get('email_from') or msg_sudo.email_from)
author_id = msg_vals.get('author_id') or msg_sudo.author_id.id
@@ -525,7 +525,7 @@ class Channel(models.Model):
'groups': [],
})
return {'partners': recipients_data, 'channels': []}
return recipients_data
def _notify_get_groups(self, msg_vals=None):
""" All recipients of a message on a channel are considered as partners.
+11 -13
View File
@@ -2082,7 +2082,7 @@ class MailThread(models.AbstractModel):
msg_vals = msg_vals if msg_vals else {}
rdata = self._notify_compute_recipients(message, msg_vals)
if not rdata:
return False
return rdata
self._notify_record_by_inbox(message, rdata, msg_vals=msg_vals, **kwargs)
if notify_by_email:
@@ -2100,7 +2100,7 @@ class MailThread(models.AbstractModel):
and correctly override notify_recipients
"""
bus_notifications = []
inbox_pids = [r['id'] for r in recipients_data['partners'] if r['notif'] == 'inbox']
inbox_pids = [r['id'] for r in recipients_data if r['notif'] == 'inbox']
if inbox_pids:
notif_create_values = [{
'mail_message_id': message.id,
@@ -2137,7 +2137,7 @@ class MailThread(models.AbstractModel):
:param send_after_commit: if force_send, tells whether to send emails after
the transaction has been committed using a post-commit hook;
"""
partners_data = [r for r in recipients_data['partners'] if r['notif'] == 'email']
partners_data = [r for r in recipients_data if r['notif'] == 'email']
if not partners_data:
return True
@@ -2352,13 +2352,11 @@ class MailThread(models.AbstractModel):
message_type = msg_vals.get('message_type') if msg_vals else msg_sudo.message_type
subtype_id = msg_vals.get('subtype_id') if msg_vals else msg_sudo.subtype_id.id
# is it possible to have record but no subtype_id ?
recipient_data = {
'partners': [],
'channels': [],
}
recipients_data = []
res = self.env['mail.followers']._get_recipient_data(self, message_type, subtype_id, pids)
if not res:
return recipient_data
return recipients_data
author_id = msg_vals.get('author_id') or message.author_id.id
for pid, active, pshare, notif, groups in res:
@@ -2369,15 +2367,15 @@ class MailThread(models.AbstractModel):
continue
pdata = {'id': pid, 'active': active, 'share': pshare, 'groups': groups or []}
if notif == 'inbox':
recipient_data['partners'].append(dict(pdata, notif=notif, type='user'))
recipients_data.append(dict(pdata, notif=notif, type='user'))
elif not pshare and notif: # has an user and is not shared, is therefore user
recipient_data['partners'].append(dict(pdata, notif=notif, type='user'))
recipients_data.append(dict(pdata, notif=notif, type='user'))
elif pshare and notif: # has an user but is shared, is therefore portal
recipient_data['partners'].append(dict(pdata, notif=notif, type='portal'))
recipients_data.append(dict(pdata, notif=notif, type='portal'))
else: # has no user, is therefore customer
recipient_data['partners'].append(dict(pdata, notif=notif if notif else 'email', type='customer'))
recipients_data.append(dict(pdata, notif=notif if notif else 'email', type='customer'))
return recipient_data
return recipients_data
@api.model
def _notify_encode_link(self, base_link, params):
+1 -1
View File
@@ -80,7 +80,7 @@ class Invite(models.TransientModel):
else: # has no user, is therefore customer
partners_data.append(dict(pdata, type='customer'))
document._notify_record_by_email(message, {'partners': partners_data, 'channels': []}, send_after_commit=False)
document._notify_record_by_email(message, partners_data, send_after_commit=False)
# in case of failure, the web client must know the message was
# deleted to discard the related failure notification
self.env['bus.bus'].sendone(
+1 -1
View File
@@ -73,7 +73,7 @@ class MailResendMessage(models.TransientModel):
else: # has no user, is therefore customer
email_partners_data.append(dict(pdata, type='customer'))
record._notify_record_by_email(message, {'partners': email_partners_data}, check_existing=True, send_after_commit=False)
record._notify_record_by_email(message, email_partners_data, check_existing=True, send_after_commit=False)
self.mail_message_id._notify_message_notification_update()
return {'type': 'ir.actions.act_window_close'}
+1 -1
View File
@@ -269,7 +269,7 @@ class MailThread(models.AbstractModel):
}
# notify from computed recipients_data (followers, specific recipients)
partners_data = [r for r in recipients_data['partners'] if r['notif'] == 'sms']
partners_data = [r for r in recipients_data if r['notif'] == 'sms']
partner_ids = [r['id'] for r in partners_data]
if partner_ids:
for partner in self.env['res.partner'].sudo().browse(partner_ids):
+1 -1
View File
@@ -91,7 +91,7 @@ class SMSResend(models.TransientModel):
rdata.append({'id': pid, 'share': pshare, 'active': active, 'notif': notif, 'groups': groups or [], 'type': 'customer' if pshare else 'user'})
if rdata or numbers:
record._notify_record_by_sms(
self.mail_message_id, {'partners': rdata}, check_existing=True,
self.mail_message_id, rdata, check_existing=True,
sms_numbers=numbers, sms_pid_to_number=sms_pid_to_number,
put_in_queue=False
)
+1 -1
View File
@@ -41,7 +41,7 @@ class TestSMSPost(TestMailFullCommon, TestMailFullRecipients):
with self.with_user('employee'), self.mockSMSGateway():
test_record = self.env['mail.test.sms'].browse(self.test_record.id)
test_record._notify_record_by_sms(messages, {'partners': [{'id': self.partner_1.id, 'notif': 'sms'}]}, check_existing=True)
test_record._notify_record_by_sms(messages, [{'id': self.partner_1.id, 'notif': 'sms'}], check_existing=True)
self.assertSMSNotification([{'partner': self.partner_1}], self._test_body, messages)
def test_message_sms_internals_sms_numbers(self):