From ff60189b5ff2739478296e7f419d4c5e438dd3c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Wed, 17 Jan 2024 10:15:41 +0100 Subject: [PATCH] [IMP] mail: add an helper for notification scheduled date Just extract some code we should otherwise copy in both mail_mobile and mail_enterprise. Task-3695571 Related to Task-3669738 (Mail: Web Push Models Rename and Fixes) X-original-commit: a6b0e88d00e1dcd4abbc1e37d62d65063c6956de Part-of: odoo/odoo#150011 --- addons/mail/models/mail_thread.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/addons/mail/models/mail_thread.py b/addons/mail/models/mail_thread.py index 2467daa741d..09c0a7eac29 100644 --- a/addons/mail/models/mail_thread.py +++ b/addons/mail/models/mail_thread.py @@ -2947,6 +2947,25 @@ class MailThread(models.AbstractModel): 'subtitles', } + @api.model + def _is_notification_scheduled(self, notify_cheduled_date): + """ Helper to check if notification are about to be scheduled. Eases + overrides. + + :param notify_scheduled_date: value of 'scheduled_date' given in + notification parameters: arbitrary datetime (as a date, datetime or + a string), may be void. See 'MailMail._parse_scheduled_datetime()'; + + :return bool: True if a valid datetime has been found and is in the + future; False otherwise. + """ + if notify_cheduled_date: + parsed_datetime = self.env['mail.mail']._parse_scheduled_datetime(notify_cheduled_date) + notify_cheduled_date = parsed_datetime.replace(tzinfo=None) if parsed_datetime else False + return ( + notify_cheduled_date and notify_cheduled_date > datetime.datetime.utcnow() + ) + def _raise_for_invalid_parameters(self, parameter_names, forbidden_names=None, restricting_names=None): """ Helper to warn about invalid parameters (or fields).