From 364b4ba06dca262d9e72f1c41444a158fb112505 Mon Sep 17 00:00:00 2001 From: Yannick Tivisse Date: Fri, 20 Nov 2015 14:24:55 +0100 Subject: [PATCH] [ADD] Add a scheduled date mechanism on email templates And use this new features to send the email template defined in the last commit on the module installation. --- addons/mail/models/mail_mail.py | 10 +++++++++- addons/mail/models/mail_template.py | 3 ++- addons/mail/views/mail_mail_views.xml | 1 + addons/mail/views/mail_template_views.xml | 1 + addons/mail/wizard/email_template_preview_view.xml | 2 ++ 5 files changed, 15 insertions(+), 2 deletions(-) diff --git a/addons/mail/models/mail_mail.py b/addons/mail/models/mail_mail.py index 0845497d10c..98f43005279 100644 --- a/addons/mail/models/mail_mail.py +++ b/addons/mail/models/mail_mail.py @@ -1,7 +1,9 @@ # -*- coding: utf-8 -*- import base64 +import datetime import logging + from email.utils import formataddr from urlparse import urljoin @@ -50,6 +52,8 @@ class MailMail(models.Model): failure_reason = fields.Text( 'Failure Reason', readonly=1, help="Failure reason. This is usually the exception thrown by the email server, stored to ease the debugging of mailing issues.") + scheduled_date = fields.Char('Scheduled Send Date', + help="If set, the queue manager will send the email after the date. If not set, the email will be send as soon as possible.") @api.model def create(self, values): @@ -98,7 +102,11 @@ class MailMail(models.Model): messages are sent). """ if not self.ids: - filters = [('state', '=', 'outgoing')] + filters = ['&', + ('state', '=', 'outgoing'), + '|', + ('scheduled_date', '<', datetime.datetime.now()), + ('scheduled_date', '=', False)] if 'filters' in self._context: filters.extend(self._context['filters']) ids = self.search(filters).ids diff --git a/addons/mail/models/mail_template.py b/addons/mail/models/mail_template.py index 19aee797c3b..f9ce655e855 100644 --- a/addons/mail/models/mail_template.py +++ b/addons/mail/models/mail_template.py @@ -160,6 +160,7 @@ class MailTemplate(models.Model): "destination document model (sub-model).") null_value = fields.Char('Default Value', help="Optional value to use if the target field is empty") copyvalue = fields.Char('Placeholder Expression', help="Final placeholder expression, to be copy-pasted in the desired template field.") + scheduled_date = fields.Char('Scheduled Date', help="If set, the queue manager will send the email after the date. If not set, the email will be send as soon as possible. Jinja2 placeholders may be used.") @api.onchange('model_id') def onchange_model_id(self): @@ -433,7 +434,7 @@ class MailTemplate(models.Model): res_ids = [res_ids] multi_mode = False if fields is None: - fields = ['subject', 'body_html', 'email_from', 'email_to', 'partner_to', 'email_cc', 'reply_to'] + fields = ['subject', 'body_html', 'email_from', 'email_to', 'partner_to', 'email_cc', 'reply_to', 'scheduled_date'] res_ids_to_templates = self.get_email_template_batch(res_ids) diff --git a/addons/mail/views/mail_mail_views.xml b/addons/mail/views/mail_mail_views.xml index e459576741a..0902212f026 100644 --- a/addons/mail/views/mail_mail_views.xml +++ b/addons/mail/views/mail_mail_views.xml @@ -27,6 +27,7 @@ + diff --git a/addons/mail/views/mail_template_views.xml b/addons/mail/views/mail_template_views.xml index 8514dabe38e..db71abc1416 100644 --- a/addons/mail/views/mail_template_views.xml +++ b/addons/mail/views/mail_template_views.xml @@ -59,6 +59,7 @@ + diff --git a/addons/mail/wizard/email_template_preview_view.xml b/addons/mail/wizard/email_template_preview_view.xml index a108c92cc33..41727385cf0 100644 --- a/addons/mail/wizard/email_template_preview_view.xml +++ b/addons/mail/wizard/email_template_preview_view.xml @@ -22,6 +22,8 @@ attrs="{'invisible':[('email_cc','=',False)]}"/> +