[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:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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}'/>
|
||||
|
||||
Reference in New Issue
Block a user