From c4dacc24facc44364c815f98bf01bfce0773f878 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Wed, 17 Mar 2021 15:00:24 +0000 Subject: [PATCH] [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 --- addons/mail/models/mail_channel.py | 6 ++--- addons/mail/models/mail_thread.py | 24 +++++++++----------- addons/mail/wizard/invite.py | 2 +- addons/mail/wizard/mail_resend_message.py | 2 +- addons/sms/models/mail_thread.py | 2 +- addons/sms/wizard/sms_resend.py | 2 +- addons/test_mail_full/tests/test_sms_post.py | 2 +- 7 files changed, 19 insertions(+), 21 deletions(-) diff --git a/addons/mail/models/mail_channel.py b/addons/mail/models/mail_channel.py index 00f7b5de214..fbc56cde19b 100644 --- a/addons/mail/models/mail_channel.py +++ b/addons/mail/models/mail_channel.py @@ -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. diff --git a/addons/mail/models/mail_thread.py b/addons/mail/models/mail_thread.py index 7ab03b8f523..98349aa5308 100644 --- a/addons/mail/models/mail_thread.py +++ b/addons/mail/models/mail_thread.py @@ -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): diff --git a/addons/mail/wizard/invite.py b/addons/mail/wizard/invite.py index b9659fb5543..5d31761a929 100644 --- a/addons/mail/wizard/invite.py +++ b/addons/mail/wizard/invite.py @@ -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( diff --git a/addons/mail/wizard/mail_resend_message.py b/addons/mail/wizard/mail_resend_message.py index e6568ed184f..c54e91a01b6 100644 --- a/addons/mail/wizard/mail_resend_message.py +++ b/addons/mail/wizard/mail_resend_message.py @@ -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'} diff --git a/addons/sms/models/mail_thread.py b/addons/sms/models/mail_thread.py index bda92a5a87b..41a1a54de63 100644 --- a/addons/sms/models/mail_thread.py +++ b/addons/sms/models/mail_thread.py @@ -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): diff --git a/addons/sms/wizard/sms_resend.py b/addons/sms/wizard/sms_resend.py index b7eb6395820..804c3d19ba3 100644 --- a/addons/sms/wizard/sms_resend.py +++ b/addons/sms/wizard/sms_resend.py @@ -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 ) diff --git a/addons/test_mail_full/tests/test_sms_post.py b/addons/test_mail_full/tests/test_sms_post.py index 2a6607f817b..a3c91bf3c30 100644 --- a/addons/test_mail_full/tests/test_sms_post.py +++ b/addons/test_mail_full/tests/test_sms_post.py @@ -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):