From c5afd7c30f99164d2eeedfd9455748db9f80acec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 8 Jul 2022 14:42:18 +0000 Subject: [PATCH] [IMP] mail: allow to update scheduled date of notifications when updating content MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- addons/mail/models/mail_thread.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/addons/mail/models/mail_thread.py b/addons/mail/models/mail_thread.py index c6b1ffab8ee..7369145896e 100644 --- a/addons/mail/models/mail_thread.py +++ b/addons/mail/models/mail_thread.py @@ -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()