diff --git a/addons/email_template/email_template.py b/addons/email_template/email_template.py
index 6fbd13a9599..3917b3f2ddb 100644
--- a/addons/email_template/email_template.py
+++ b/addons/email_template/email_template.py
@@ -360,18 +360,18 @@ class email_template(osv.osv):
and schedule it for delivery through the ``mail`` module's scheduler.
:param int template_id: id of the template to render
- :param int record_id: id of the record to render the template with
- (model is taken from the template)
+ :param int res_id: id of the record to render the template with
+ (model is taken from the template)
"""
mail_message = self.pool.get('mail.message')
ir_attachment = self.pool.get('ir.attachment')
template = self.browse(cr, uid, template_id, context)
values = self.generate_email(cr, uid, template_id, res_id, context=context)
- attachments = values.pop('attachments')
- message_id = mail_message.create(values)
+ attachments = values.pop('attachments') or {}
+ message_id = mail_message.create(cr, uid, values, context=context)
# link attachments
attachment_ids = []
- for fname, fcontent in values['attachments'].iteritems():
+ for fname, fcontent in attachments.iteritems():
attachment_data = {
'name': fname,
'datas_fname': fname,
diff --git a/addons/email_template/email_template_view.xml b/addons/email_template/email_template_view.xml
index fe460d8829d..b4f76a03c6c 100644
--- a/addons/email_template/email_template_view.xml
+++ b/addons/email_template/email_template_view.xml
@@ -31,10 +31,10 @@
-
+
-
+
diff --git a/addons/email_template/wizard/email_template_preview.py b/addons/email_template/wizard/email_template_preview.py
index 7d316da8626..650b714866d 100644
--- a/addons/email_template/wizard/email_template_preview.py
+++ b/addons/email_template/wizard/email_template_preview.py
@@ -57,11 +57,11 @@ class email_template_preview(osv.osv_memory):
result = super(email_template_preview, self).default_get(cr, uid, fields, context=context)
email_template = self.pool.get('email.template')
- template_id = context.get('active_id', False)
- if 'res_id' in fields:
+ template_id = context.get('template_id')
+ if 'res_id' in fields and not result.get('res_id'):
records = self._get_records(cr, uid, context=context)
result['res_id'] = records and records[0][0] or False # select first record as a Default
- if template_id and 'model_id' in fields:
+ if template_id and 'model_id' in fields and not result.get('model_id'):
result['model_id'] = email_template.read(cr, uid, int(template_id), ['model_id'], context).get('model_id', False)
return result
@@ -69,18 +69,13 @@ class email_template_preview(osv.osv_memory):
'res_id':fields.selection(_get_records, 'Sample Document'),
}
- def on_change_ref(self, cr, uid, ids, res_id, context=None):
- if context is None:
- context = {}
+ def on_change_res_id(self, cr, uid, ids, res_id, context=None):
if not res_id:
return {}
vals = {}
- if context == {}:
- context = self.context
-
- template_pool = self.pool.get('email.template')
- template_id = context.get('template_id', False)
- template = template_pool.get_email_template(cr, uid, template_id=template_id, record_id=res_id, context=context)
+ email_template = self.pool.get('email.template')
+ template_id = context and context.get('template_id')
+ template = email_template.get_email_template(cr, uid, template_id=template_id, record_id=res_id, context=context)
model = template.model
vals['email_to'] = self.render_template(cr, uid, template.email_to, model, res_id, context)
vals['email_cc'] = self.render_template(cr, uid, template.email_cc, model, res_id, context)
diff --git a/addons/email_template/wizard/email_template_preview_view.xml b/addons/email_template/wizard/email_template_preview_view.xml
index 80d3e558ef4..4aab57396ad 100644
--- a/addons/email_template/wizard/email_template_preview_view.xml
+++ b/addons/email_template/wizard/email_template_preview_view.xml
@@ -8,26 +8,31 @@
form
diff --git a/addons/marketing_campaign/marketing_campaign.py b/addons/marketing_campaign/marketing_campaign.py
index e9bfd2ca694..27c91fcc3fe 100644
--- a/addons/marketing_campaign/marketing_campaign.py
+++ b/addons/marketing_campaign/marketing_campaign.py
@@ -144,13 +144,6 @@ Normal - the campaign runs normally and automatically sends all emails and repor
if activity.signal and len(activity.from_ids) == 0:
has_signal_without_from = True
- if activity.type != 'email':
- continue
- if not activity.email_template_id.from_account:
- raise osv.except_osv(_("Error"), _("The campaign cannot be started: the email account is missing in email activity '%s'")%activity.name)
- if activity.email_template_id.from_account.state != 'approved':
- raise osv.except_osv(_("Error"), _("The campaign cannot be started: the email account is not approved in email activity '%s'")%activity.name)
-
if not has_start and not has_signal_without_from:
raise osv.except_osv(_("Error"), _("The campaign cannot be started: it doesn't have any starting activity (or any activity with a signal and no previous activity)"))
@@ -486,7 +479,7 @@ class marketing_campaign_activity(osv.osv):
def _process_wi_email(self, cr, uid, activity, workitem, context=None):
return self.pool.get('email.template').send_mail(cr, uid,
activity.email_template_id.id,
- [workitem.res_id], context=context)
+ workitem.res_id, context=context)
def _process_wi_action(self, cr, uid, activity, workitem, context=None):
if context is None:
@@ -807,7 +800,7 @@ class marketing_campaign_workitem(osv.osv):
'type': 'ir.actions.act_window',
'target': 'new',
'nodestroy':True,
- 'context': "{'template_id':%d,'default_rel_model_ref':%d}"%
+ 'context': "{'template_id':%d,'default_res_id':%d}"%
(wi_obj.activity_id.email_template_id.id,
wi_obj.res_id)
}