summaryrefslogtreecommitdiff
path: root/addons/mail/wizard/mail_resend_message.py
diff options
context:
space:
mode:
authorThibault Delavallée <tde@odoo.com>2019-05-22 15:10:54 +0000
committerThibault Delavallée <tde@odoo.com>2019-07-12 14:54:11 +0000
commit488a5d5af5418ed5c223af5b61aea0b3100508c1 (patch)
tree796bf1e455b263f39800040b7f9f3d7c7756dc16 /addons/mail/wizard/mail_resend_message.py
parentfd15ca19183a765e1307c4d197bf0dda30b73ab7 (diff)
[IMP] mail: prepare new SMS model by updating mail.notification
This commit prepares SMS refactoring by updating some mail models. Purpose is to be able to store SMS notification information inside existing mail flow and models. Main changes * mail.notification: define a notification_type field to store the medium used to notify people. In mail two ways exist: inbox and email. It will ease introduction of SMS notification mechanism. This field replaces the is_email boolean field; * mail.notification: make res_partner_id field not required. This means notifications could be linked to something else than a partner. An SMS for example. For Inbox and email notifications partner is still required and a constraint is added accordingly; * mail.thread: let notification methods handle the creation and update of their notification instead of creating them in _notify_thread and tweaking them in sub notification methods; * mail.thread: clearly move inbox-style notification in its own method like notify by email; Some lighter code changes * propagate message_type to notification recipient computation. It will allow for example to be more precise when computing a notification type depending on the message_type. For example, send a notification by SMS when the message_type is SMS; * ease inheritance of ``_notify_thread`` by returning computed recipients data. It will allow to work on it without having to re-compute it; * propagate kwargs from message_post and message_notify to notify methods. This allow to avoid depending on context and set explicit parameters. Drawback is that message_post and notify must separate kwargs used to create a message and those that are propagated to notification methods; * update various notification check to ensure they work on email notifications, notably the resend and cancel wizards; One side effect of this commit is that notifications are created by the relevant notification method. Previously all notifications were created by writing on needaction_partner_ids fields then updated according to the notification process. Notably there could be too much notification created when sending emails due to _notify_customize_recipients not being correctly synchronized with notification. This issue is now solved as only really sent emails create notifications. Migration tips * notification_type: notification.is_email and 'email' else 'inbox'; * remove is_email; Related to task 1922163 Linked to PR #33510
Diffstat (limited to 'addons/mail/wizard/mail_resend_message.py')
-rw-r--r--addons/mail/wizard/mail_resend_message.py32
1 files changed, 15 insertions, 17 deletions
diff --git a/addons/mail/wizard/mail_resend_message.py b/addons/mail/wizard/mail_resend_message.py
index e5e4c069df1..9c72944961b 100644
--- a/addons/mail/wizard/mail_resend_message.py
+++ b/addons/mail/wizard/mail_resend_message.py
@@ -28,16 +28,14 @@ class MailResendMessage(models.TransientModel):
message_id = self._context.get('mail_message_to_resend')
if message_id:
mail_message_id = self.env['mail.message'].browse(message_id)
- notification_ids = mail_message_id.notification_ids.filtered(lambda notif: notif.email_status in ('exception', 'bounce'))
- partner_ids = [(0, 0,
- {
- "partner_id": notif.res_partner_id.id,
- "name": notif.res_partner_id.name,
- "email": notif.res_partner_id.email,
- "resend": True,
- "message": notif.format_failure_reason(),
- }
- ) for notif in notification_ids]
+ notification_ids = mail_message_id.notification_ids.filtered(lambda notif: notif.notification_type == 'email' and notif.notification_status in ('exception', 'bounce'))
+ partner_ids = [(0, 0, {
+ "partner_id": notif.res_partner_id.id,
+ "name": notif.res_partner_id.name,
+ "email": notif.res_partner_id.email,
+ "resend": True,
+ "message": notif.format_failure_reason(),
+ }) for notif in notification_ids]
has_user = any([notif.res_partner_id.user_ids for notif in notification_ids])
if has_user:
partner_readonly = not self.env['res.users'].check_access_rights('write', raise_exception=False)
@@ -59,14 +57,14 @@ class MailResendMessage(models.TransientModel):
"If a partner disappeared from partner list, we cancel the notification"
to_cancel = wizard.partner_ids.filtered(lambda p: not p.resend).mapped("partner_id")
to_send = wizard.partner_ids.filtered(lambda p: p.resend).mapped("partner_id")
- notif_to_cancel = wizard.notification_ids.filtered(lambda notif: notif.res_partner_id in to_cancel and notif.email_status in ('exception', 'bounce'))
- notif_to_cancel.sudo().write({'email_status': 'canceled'})
+ notif_to_cancel = wizard.notification_ids.filtered(lambda notif: notif.notification_type == 'email' and notif.res_partner_id in to_cancel and notif.notification_status in ('exception', 'bounce'))
+ notif_to_cancel.sudo().write({'notification_status': 'canceled'})
if to_send:
message = wizard.mail_message_id
record = self.env[message.model].browse(message.res_id) if message.is_thread_message() else self.env['mail.thread']
email_partners_data = []
- for pid, cid, active, pshare, ctype, notif, groups in self.env['mail.followers']._get_recipient_data(None, False, pids=to_send.ids):
+ for pid, cid, active, pshare, ctype, notif, groups in self.env['mail.followers']._get_recipient_data(None, 'comment', False, pids=to_send.ids):
if pid and notif == 'email' or not notif:
pdata = {'id': pid, 'share': pshare, 'active': active, 'notif': 'email', 'groups': groups or []}
if not pshare and notif: # has an user and is not shared, is therefore user
@@ -76,17 +74,17 @@ 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, email_partners_data, send_after_commit=False)
+ record._notify_record_by_email(message, {'partners': email_partners_data}, check_existing=True, send_after_commit=False)
- self.mail_message_id._notify_failure_update()
+ self.mail_message_id._notify_mail_failure_update()
return {'type': 'ir.actions.act_window_close'}
@api.multi
def cancel_mail_action(self):
for wizard in self:
for notif in wizard.notification_ids:
- notif.filtered(lambda notif: notif.email_status in ('exception', 'bounce')).sudo().write({'email_status': 'canceled'})
- wizard.mail_message_id._notify_failure_update()
+ notif.filtered(lambda notif: notif.notification_type == 'email' and notif.notification_status in ('exception', 'bounce')).sudo().write({'notification_status': 'canceled'})
+ wizard.mail_message_id._notify_mail_failure_update()
return {'type': 'ir.actions.act_window_close'}