summaryrefslogtreecommitdiff
path: root/addons/email_template/wizard
diff options
context:
space:
mode:
authorRandhir Mayatra (OpenERP) <rma@tinyerp.com>2012-11-19 16:38:24 +0530
committerRandhir Mayatra (OpenERP) <rma@tinyerp.com>2012-11-19 16:38:24 +0530
commitd23c5c8dca985dd0fde280c9237dee85b7bb4d7a (patch)
treecf03bc2a74a1d9e93b5ef571fb78070c09c9857b /addons/email_template/wizard
parentf4ab81afb8285a8157258232c5fb2a6745ae7f72 (diff)
parent66afff1b52b7ab6ab8c340e18960fb6367cfb714 (diff)
[MERGE]merge with trunk
bzr revid: rma@tinyerp.com-20121119110824-rj4y32rfbszqln7g
Diffstat (limited to 'addons/email_template/wizard')
-rw-r--r--addons/email_template/wizard/email_template_preview_view.xml1
-rw-r--r--addons/email_template/wizard/mail_compose_message.py45
-rw-r--r--addons/email_template/wizard/mail_compose_message_view.xml31
3 files changed, 52 insertions, 25 deletions
diff --git a/addons/email_template/wizard/email_template_preview_view.xml b/addons/email_template/wizard/email_template_preview_view.xml
index f91535a17a5..8dd4bc92ba7 100644
--- a/addons/email_template/wizard/email_template_preview_view.xml
+++ b/addons/email_template/wizard/email_template_preview_view.xml
@@ -17,6 +17,7 @@
<group>
<field name="email_from" readonly="1"/>
<field name="email_to" readonly="1"/>
+ <field name="email_recipients" readonly="1"/>
<field name="email_cc" readonly="1" attrs="{'invisible':[('email_cc','=',False)]}"/>
<field name="reply_to" readonly="1" attrs="{'invisible':[('reply_to','=',False)]}"/>
<field name="subject" readonly="1"/>
diff --git a/addons/email_template/wizard/mail_compose_message.py b/addons/email_template/wizard/mail_compose_message.py
index fe6f85da544..e9141029166 100644
--- a/addons/email_template/wizard/mail_compose_message.py
+++ b/addons/email_template/wizard/mail_compose_message.py
@@ -25,6 +25,21 @@ from osv import osv
from osv import fields
+def _reopen(self, res_id, model):
+ return {'type': 'ir.actions.act_window',
+ 'view_mode': 'form',
+ 'view_type': 'form',
+ 'res_id': res_id,
+ 'res_model': self._name,
+ 'target': 'new',
+ # save original model in context, because selecting the list of available
+ # templates requires a model in context
+ 'context': {
+ 'default_model': model,
+ },
+ }
+
+
class mail_compose_message(osv.TransientModel):
_inherit = 'mail.compose.message'
@@ -42,18 +57,17 @@ class mail_compose_message(osv.TransientModel):
else:
model = context.get('default_model', context.get('active_model'))
- if model:
- record_ids = email_template_obj.search(cr, uid, [('model', '=', model)], context=context)
- return email_template_obj.name_get(cr, uid, record_ids, context) + [(False, '')]
- return []
+ record_ids = email_template_obj.search(cr, uid, [('model', '=', model)], context=context)
+ return email_template_obj.name_get(cr, uid, record_ids, context) + [(False, '')]
def default_get(self, cr, uid, fields, context=None):
if context is None:
context = {}
result = super(mail_compose_message, self).default_get(cr, uid, fields, context=context)
result['template_id'] = context.get('default_template_id', context.get('mail.compose.template_id', False))
+
# pre-render the template if any
- if result.get('use_template'):
+ if result.get('use_template') and result.get('template_id'):
onchange_res = self.onchange_use_template(cr, uid, [], result.get('use_template'), result.get('template_id'),
result.get('composition_mode'), result.get('model'), result.get('res_id'), context=context)
result.update(onchange_res['value'])
@@ -65,6 +79,10 @@ class mail_compose_message(osv.TransientModel):
'template_id': fields.selection(_get_templates, 'Template', size=-1),
}
+ _defaults = {
+ 'use_template': True,
+ }
+
def onchange_template_id(self, cr, uid, ids, use_template, template_id, composition_mode, model, res_id, context=None):
""" - use_template not set: return default_get
- use_template set in mass_mailing: we cannot render, so return the template values
@@ -84,6 +102,7 @@ class mail_compose_message(osv.TransientModel):
'datas_fname': attach_fname,
'res_model': model,
'res_id': res_id,
+ 'type': 'binary', # overwrite the context default_value
}
values['attachment_ids'].append(ir_attach_obj.create(cr, uid, data_attach, context=context))
else:
@@ -104,7 +123,7 @@ class mail_compose_message(osv.TransientModel):
onchange_res['partner_ids'] = [(4, partner_id) for partner_id in onchange_res.pop('partner_ids', [])]
onchange_res['attachment_ids'] = [(4, attachment_id) for attachment_id in onchange_res.pop('attachment_ids', [])]
record.write(onchange_res)
- return True
+ return _reopen(self, record.id, record.model)
def onchange_use_template(self, cr, uid, ids, use_template, template_id, composition_mode, model, res_id, context=None):
""" onchange_use_template (values: True or False). If use_template is
@@ -136,8 +155,8 @@ class mail_compose_message(osv.TransientModel):
'attachment_ids': [(6, 0, [att.id for att in record.attachment_ids])]
}
template_id = email_template.create(cr, uid, values, context=context)
- record.write({'template_id': template_id, 'use_template': True})
- return True
+ record.write(record.onchange_template_id(True, template_id, record.composition_mode, record.model, record.res_id)['value'])
+ return _reopen(self, record.id, record.model)
#------------------------------------------------------
# Wizard validation and send
@@ -148,15 +167,23 @@ class mail_compose_message(osv.TransientModel):
mail.compose.message, transform email_cc and email_to into partner_ids """
template_values = self.pool.get('email.template').generate_email(cr, uid, template_id, res_id, context=context)
# filter template values
- fields = ['body', 'body_html', 'subject', 'email_to', 'email_cc', 'attachments']
+ fields = ['body', 'body_html', 'subject', 'email_to', 'email_recipients', 'email_cc', 'attachments']
values = dict((field, template_values[field]) for field in fields if template_values.get(field))
values['body'] = values.pop('body_html', '')
# transform email_to, email_cc into partner_ids
values['partner_ids'] = []
+
mails = tools.email_split(values.pop('email_to', '') + ' ' + values.pop('email_cc', ''))
for mail in mails:
partner_id = self.pool.get('res.partner').find_or_create(cr, uid, mail, context=context)
values['partner_ids'].append(partner_id)
+ email_recipients = values.pop('email_recipients', '')
+ if email_recipients:
+ for partner_id in email_recipients.split(','):
+ values['partner_ids'].append(int(partner_id))
+
+ values['partner_ids'] = list(set(values['partner_ids']))
+
return values
def render_message(self, cr, uid, wizard, res_id, context=None):
diff --git a/addons/email_template/wizard/mail_compose_message_view.xml b/addons/email_template/wizard/mail_compose_message_view.xml
index 05d0e8dffa1..5afaf9745e1 100644
--- a/addons/email_template/wizard/mail_compose_message_view.xml
+++ b/addons/email_template/wizard/mail_compose_message_view.xml
@@ -8,23 +8,22 @@
<field name="inherit_id" ref="mail.email_compose_message_wizard_form"/>
<field name="arch" type="xml">
<data>
- <xpath expr="//form/group" position="after">
- <group attrs="{'invisible':[('use_template','=',False)]}">
- <field name="use_template" invisible="1"
- on_change="onchange_use_template(use_template, template_id, composition_mode, model, res_id, context)"/>
- <field name="template_id"
- on_change="onchange_template_id(use_template, template_id, composition_mode, model, res_id, context)"/>
- </group>
+ <xpath expr="//field[@name='content_subtype']" position="after">
+ <field name="use_template" invisible="1"
+ on_change="onchange_use_template(use_template, template_id, composition_mode, model, res_id, context)"/>
</xpath>
- <xpath expr="//form/footer/button" position="after">
- <button icon="/email_template/static/src/img/email_template.png"
- type="object" name="toggle_template" string=""
- help="Use a message template"
- attrs="{'invisible':[('content_subtype','!=','html')]}"/>
- <button icon="/email_template/static/src/img/email_template_save.png"
- type="object" name="save_as_template" string=""
- help="Save as a new template"
- attrs="{'invisible':[('content_subtype','!=','html')]}"/>
+ <xpath expr="//footer" position="inside">
+ <group class="oe_right" col="1">
+ <div attrs="{'invisible':[('use_template','=',False)]}">Use template
+ <field name="template_id" attrs="{'invisible':[('use_template','=',False)]}"
+ nolabel="1"
+ on_change="onchange_template_id(use_template, template_id, composition_mode, model, res_id, context)"/>
+ </div>
+ <button icon="/email_template/static/src/img/email_template_save.png"
+ type="object" name="save_as_template" string="Save as new template" class="oe_link"
+ help="Save as a new template"
+ attrs="{'invisible':[('content_subtype','!=','html')]}"/>
+ </group>
</xpath>
</data>
</field>