[IMP] mail: allow to update scheduled date of notifications when updating content

Purpose of this commit is to allow to update the scheduled date when using
``_message_update_content`` tool method. This allows notably to delay the
sending of notifications in some cases, then send it once all content is
updated according to business requirements.

When giving a scheduled date in kwargs

  * either it is set, and we update message schedulers accordingly;
  * either we force a void value, which means notification should be done
    now and we trigger the schedulers for immediate sending;

Task-2207626 (Rating: Delay rating notification to ease feedback)

Part-of: odoo/odoo#95623
Co-authored-by: Stéphane Debauche <std@odoo.com>
This commit is contained in:
Thibault Delavallée
2022-08-25 19:57:17 +02:00
co-authored by Stéphane Debauche
parent 9b11a9d82b
commit c5afd7c30f
+15 -1
View File
@@ -3171,7 +3171,7 @@ class MailThread(models.AbstractModel):
return True
def _message_update_content(self, message, body, attachment_ids=None,
strict=True):
strict=True, **kwargs):
""" Update message content. Currently does not support attachments
specific code (see ``_message_post_process_attachments``), to be added
when necessary.
@@ -3189,6 +3189,9 @@ class MailThread(models.AbstractModel):
content. This should be skipped only when really necessary as it
creates issues with already-sent notifications, lack of content
tracking, ...
Kwargs are supported, notably to match mail.message fields to update.
See content of this method for more details about supported keys.
"""
self.ensure_one()
if strict:
@@ -3208,6 +3211,17 @@ class MailThread(models.AbstractModel):
if msg_values:
message.write(msg_values)
if 'scheduled_date' in kwargs:
# update scheduled datetime
if kwargs['scheduled_date']:
self.env['mail.message.schedule'].sudo()._update_message_scheduled_datetime(
message,
kwargs['scheduled_date']
)
# (re)send notifications
else:
self.env['mail.message.schedule'].sudo()._send_message_notifications(message)
# cleanup related message data if the message is empty
message.sudo()._filter_empty()._cleanup_side_records()