summaryrefslogtreecommitdiff
path: root/addons/email_template/wizard
diff options
context:
space:
mode:
authorchm@openerp.com <>2014-04-23 17:48:52 +0200
committerchm@openerp.com <>2014-04-23 17:48:52 +0200
commitee7ff4bd07d8d84ed2ebb0e2e3f5eb437f158e5b (patch)
tree25577845139d390f9bf27e0237d18842aeace02b /addons/email_template/wizard
parentb1bc68d8eb374f30173e03e8048d1c3588a00d4b (diff)
parent1657ffb8e7d95ef5f94e59121737abb068371b66 (diff)
[MERGE] from trunk
bzr revid: chm@openerp.com-20140423154852-gzegxqrzb2sj01zl
Diffstat (limited to 'addons/email_template/wizard')
-rw-r--r--addons/email_template/wizard/email_template_preview.py3
-rw-r--r--addons/email_template/wizard/email_template_preview_view.xml15
-rw-r--r--addons/email_template/wizard/mail_compose_message.py69
-rw-r--r--addons/email_template/wizard/mail_compose_message_view.xml16
4 files changed, 35 insertions, 68 deletions
diff --git a/addons/email_template/wizard/email_template_preview.py b/addons/email_template/wizard/email_template_preview.py
index 5fee415a75e..104437ec0d3 100644
--- a/addons/email_template/wizard/email_template_preview.py
+++ b/addons/email_template/wizard/email_template_preview.py
@@ -66,6 +66,7 @@ class email_template_preview(osv.osv_memory):
_columns = {
'res_id': fields.selection(_get_records, 'Sample Document'),
+ 'partner_ids': fields.many2many('res.partner', string='Recipients'),
}
def on_change_res_id(self, cr, uid, ids, res_id, context=None):
@@ -80,7 +81,7 @@ class email_template_preview(osv.osv_memory):
# generate and get template values
mail_values = email_template.generate_email(cr, uid, template_id, res_id, context=context)
- vals = dict((field, mail_values.get(field, False)) for field in ('email_from', 'email_to', 'email_cc', 'reply_to', 'subject', 'body_html', 'partner_to'))
+ vals = dict((field, mail_values.get(field, False)) for field in ('email_from', 'email_to', 'email_cc', 'reply_to', 'subject', 'body_html', 'partner_to', 'partner_ids', 'attachment_ids'))
vals['name'] = template.name
return {'value': vals}
diff --git a/addons/email_template/wizard/email_template_preview_view.xml b/addons/email_template/wizard/email_template_preview_view.xml
index 0a74f7d813e..87c1e92fa60 100644
--- a/addons/email_template/wizard/email_template_preview_view.xml
+++ b/addons/email_template/wizard/email_template_preview_view.xml
@@ -8,14 +8,17 @@
<field name="arch" type="xml">
<form string="Email Preview" version="7.0">
<field name="model_id" invisible="1"/>
- <h2 style="color: #7c7bad;">Preview of <field name="name" readonly="1" nolabel="1" class="oe_inline"/></h2>
- Using sample document <field name="res_id" on_change="on_change_res_id(res_id, context)" class="oe_inline"/>
+ <h3>Preview of <field name="name" readonly="1" nolabel="1" class="oe_inline"/></h3>
+ Choose an example <field name="model_id" class="oe_inline" readonly="1"/> record:
+ <field name="res_id" on_change="on_change_res_id(res_id, context)" class="oe_inline"
+ style="margin-left: 8px;"/>
<group>
<field name="subject" readonly="1"/>
<field name="email_from" readonly="1"
attrs="{'invisible':[('email_from','=',False)]}"/>
- <field name="email_to" readonly="1"/>
- <field name="partner_to" readonly="1"/>
+ <field name="partner_ids" widget="many2many_tags" readonly="1"/>
+ <field name="email_to" readonly="1"
+ attrs="{'invisible':[('email_to','=',False)]}"/>
<field name="email_cc" readonly="1"
attrs="{'invisible':[('email_cc','=',False)]}"/>
<field name="reply_to" readonly="1"
@@ -23,6 +26,7 @@
</group>
<field name="body_html" widget="html" readonly="1"
nolabel="1" options='{"safe": True}'/>
+ <field name="attachment_ids" widget="many2many_binary" radonly="1"/>
</form>
</field>
</record>
@@ -30,10 +34,11 @@
<record id="wizard_email_template_preview" model="ir.actions.act_window">
<field name="name">Template Preview</field>
<field name="res_model">email_template.preview</field>
- <field name="src_model">email_template.preview</field>
+ <field name="src_model">email.template</field>
<field name="type">ir.actions.act_window</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
+ <field name="view_id" ref="email_template_preview_form"/>
<field name="auto_refresh" eval="1" />
<field name="target">new</field>
<field name="context">{'template_id':active_id}</field>
diff --git a/addons/email_template/wizard/mail_compose_message.py b/addons/email_template/wizard/mail_compose_message.py
index 71f99471afa..676f11b23e3 100644
--- a/addons/email_template/wizard/mail_compose_message.py
+++ b/addons/email_template/wizard/mail_compose_message.py
@@ -42,7 +42,8 @@ class mail_compose_message(osv.TransientModel):
_inherit = 'mail.compose.message'
def default_get(self, cr, uid, fields, context=None):
- """ Override to pre-fill the data when having a template in single-email mode """
+ """ Override to pre-fill the data when having a template in single-email mode
+ and not going through the view: the on_change is not called in that case. """
if context is None:
context = {}
res = super(mail_compose_message, self).default_get(cr, uid, fields, context=context)
@@ -50,19 +51,13 @@ class mail_compose_message(osv.TransientModel):
res.update(
self.onchange_template_id(
cr, uid, [], context['default_template_id'], res.get('composition_mode'),
- res.get('model'), res.get('res_id', context.get('active_id')), context=context
+ res.get('model'), res.get('res_id'), context=context
)['value']
)
return res
_columns = {
'template_id': fields.many2one('email.template', 'Use template', select=True),
- 'partner_to': fields.char('To (Partner IDs)',
- help="Comma-separated list of recipient partners ids (placeholders may be used here)"),
- 'email_to': fields.char('To (Emails)',
- help="Comma-separated recipient addresses (placeholders may be used here)",),
- 'email_cc': fields.char('Cc (Emails)',
- help="Carbon copy recipients (placeholders may be used here)"),
}
def send_mail(self, cr, uid, ids, context=None):
@@ -92,14 +87,13 @@ class mail_compose_message(osv.TransientModel):
""" - mass_mailing: we cannot render, so return the template values
- normal mode: return rendered values """
if template_id and composition_mode == 'mass_mail':
- fields = ['subject', 'body_html', 'email_from', 'email_to', 'partner_to', 'email_cc', 'reply_to', 'attachment_ids', 'mail_server_id']
+ fields = ['subject', 'body_html', 'email_from', 'reply_to', 'attachment_ids', 'mail_server_id']
template_values = self.pool.get('email.template').read(cr, uid, template_id, fields, context)
values = dict((field, template_values[field]) for field in fields if template_values.get(field))
elif template_id:
values = self.generate_email_for_composer_batch(cr, uid, template_id, [res_id], context=context)[res_id]
# transform attachments into attachment_ids; not attached to the document because this will
# be done further in the posting process, allowing to clean database if email not send
- values['attachment_ids'] = values.pop('attachment_ids', [])
ir_attach_obj = self.pool.get('ir.attachment')
for attach_fname, attach_datas in values.pop('attachments', []):
data_attach = {
@@ -110,7 +104,7 @@ class mail_compose_message(osv.TransientModel):
'res_id': 0,
'type': 'binary', # override default_type from context, possibly meant for another model!
}
- values['attachment_ids'].append(ir_attach_obj.create(cr, uid, data_attach, context=context))
+ values.setdefault('attachment_ids', list()).append(ir_attach_obj.create(cr, uid, data_attach, context=context))
else:
values = self.default_get(cr, uid, ['subject', 'body', 'email_from', 'email_to', 'email_cc', 'partner_to', 'reply_to', 'attachment_ids', 'mail_server_id'], context=context)
@@ -148,47 +142,29 @@ class mail_compose_message(osv.TransientModel):
# Wizard validation and send
#------------------------------------------------------
- def _get_or_create_partners_from_values(self, cr, uid, rendered_values, context=None):
- """ Check for email_to, email_cc, partner_to """
- partner_ids = []
- mails = tools.email_split(rendered_values.pop('email_to', '')) + tools.email_split(rendered_values.pop('email_cc', ''))
- for mail in mails:
- partner_id = self.pool.get('res.partner').find_or_create(cr, uid, mail, context=context)
- partner_ids.append(partner_id)
- partner_to = rendered_values.pop('partner_to', '')
- if partner_to:
- # placeholders could generate '', 3, 2 due to some empty field values
- tpl_partner_ids = [pid for pid in partner_to.split(',') if pid]
- partner_ids += self.pool['res.partner'].exists(cr, SUPERUSER_ID, tpl_partner_ids, context=context)
- return partner_ids
-
def generate_email_for_composer_batch(self, cr, uid, template_id, res_ids, context=None, fields=None):
""" Call email_template.generate_email(), get fields relevant for
mail.compose.message, transform email_cc and email_to into partner_ids """
- # filter template values
+ if context is None:
+ context = {}
if fields is None:
fields = ['subject', 'body_html', 'email_from', 'email_to', 'partner_to', 'email_cc', 'reply_to', 'attachment_ids', 'mail_server_id']
- returned_fields = fields + ['attachments']
+ returned_fields = fields + ['partner_ids', 'attachments']
values = dict.fromkeys(res_ids, False)
- template_values = self.pool.get('email.template').generate_email_batch(cr, uid, template_id, res_ids, fields=fields, context=context)
+ ctx = dict(context, tpl_partners_only=True)
+ template_values = self.pool.get('email.template').generate_email_batch(cr, uid, template_id, res_ids, fields=fields, context=ctx)
for res_id in res_ids:
res_id_values = dict((field, template_values[res_id][field]) for field in returned_fields if template_values[res_id].get(field))
res_id_values['body'] = res_id_values.pop('body_html', '')
-
- # transform email_to, email_cc into partner_ids
- ctx = dict((k, v) for k, v in (context or {}).items() if not k.startswith('default_'))
- partner_ids = self._get_or_create_partners_from_values(cr, uid, res_id_values, context=ctx)
- # legacy template behavior: void values do not erase existing values and the
- # related key is removed from the values dict
- if partner_ids:
- res_id_values['partner_ids'] = list(partner_ids)
-
values[res_id] = res_id_values
return values
def render_message_batch(self, cr, uid, wizard, res_ids, context=None):
""" Override to handle templates. """
+ # generate composer values
+ composer_values = super(mail_compose_message, self).render_message_batch(cr, uid, wizard, res_ids, context)
+
# generate template-based values
if wizard.template_id:
template_values = self.generate_email_for_composer_batch(
@@ -196,17 +172,18 @@ class mail_compose_message(osv.TransientModel):
fields=['email_to', 'partner_to', 'email_cc', 'attachment_ids', 'mail_server_id'],
context=context)
else:
- template_values = dict.fromkeys(res_ids, dict())
- # generate composer values
- composer_values = super(mail_compose_message, self).render_message_batch(cr, uid, wizard, res_ids, context)
+ template_values = {}
for res_id in res_ids:
- # remove attachments from template values as they should not be rendered
- template_values[res_id].pop('attachment_ids', None)
- # remove some keys from composer that are readonly
- composer_values[res_id].pop('email_to', None)
- composer_values[res_id].pop('email_cc', None)
- composer_values[res_id].pop('partner_to', None)
+ if template_values.get(res_id):
+ # recipients are managed by the template
+ composer_values[res_id].pop('partner_ids')
+ composer_values[res_id].pop('email_to')
+ composer_values[res_id].pop('email_cc')
+ # remove attachments from template values as they should not be rendered
+ template_values[res_id].pop('attachment_ids', None)
+ else:
+ template_values[res_id] = dict()
# update template values by composer values
template_values[res_id].update(composer_values[res_id])
return template_values
diff --git a/addons/email_template/wizard/mail_compose_message_view.xml b/addons/email_template/wizard/mail_compose_message_view.xml
index 44145114fff..2f755a625d6 100644
--- a/addons/email_template/wizard/mail_compose_message_view.xml
+++ b/addons/email_template/wizard/mail_compose_message_view.xml
@@ -7,22 +7,6 @@
<field name="model">mail.compose.message</field>
<field name="inherit_id" ref="mail.email_compose_message_wizard_form"/>
<field name="arch" type="xml">
- <xpath expr="//field[@name='subject']" position="after">
- <label string="Template Recipients" for="partner_to"
- groups="base.group_no_one"
- attrs="{'invisible':[('composition_mode', '!=', 'mass_mail')]}"/>
- <div groups="base.group_no_one" name="template_recipients"
- attrs="{'invisible':[('composition_mode', '!=', 'mass_mail')]}">
- <group class="oe_grey">
- <!-- <label string="Partners" for="partner_to"/> -->
- <field name="partner_to" readonly="1"/>
- <!-- <label string="Email To" for="email_to"/> -->
- <field name="email_to" readonly="1"/>
- <!-- <label string="Email CC" for="email_cc"/> -->
- <field name="email_cc" readonly="1"/>
- </group>
- </div>
- </xpath>
<xpath expr="//footer" position="inside">
<group class="oe_right oe_form" col="1">
<div>Use template