[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.
This commit is contained in:
Yannick Tivisse
2015-11-24 18:50:27 +01:00
parent 77250b5b9a
commit 364b4ba06d
5 changed files with 15 additions and 2 deletions
+9 -1
View File
@@ -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
+2 -1
View File
@@ -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)
+1
View File
@@ -27,6 +27,7 @@
<field name="recipient_ids" widget="many2many_tags"/>
<field name="email_cc"/>
<field name="reply_to"/>
<field name="scheduled_date"/>
</group>
<notebook>
<page string="Body">
@@ -59,6 +59,7 @@
<field name="reply_to"
placeholder="Preferred reply address"/>
<field name="user_signature" string="Author Signature (mass mail only)"/>
<field name="scheduled_date" string="Scheduled Send Date"/>
</group>
</page>
<page string="Advanced Settings">
@@ -22,6 +22,8 @@
attrs="{'invisible':[('email_cc','=',False)]}"/>
<field name="reply_to" readonly="1"
attrs="{'invisible':[('reply_to','=',False)]}"/>
<field name="scheduled_date" readonly="1"
attrs="{'invisible':[('scheduled_date','=',False)]}"/>
</group>
<field name="body_html" widget="html" readonly="1"
nolabel="1" options='{"safe": True}'/>