[FIX] marketing_campaign: typos and cleanup

bzr revid: odo@openerp.com-20110912180025-scdjvcnquo07zcha
This commit is contained in:
Olivier Dony 2011-09-12 20:00:25 +02:00
parent 7b6f5176ad
commit d22c3043aa
5 changed files with 37 additions and 44 deletions

View File

@ -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,

View File

@ -31,10 +31,10 @@
<field name="subject" colspan="4" required="1"/>
<notebook>
<page string="Body (Text)">
<field name="body_text" colspan="4" nolabel="1"/>
<field name="body_text" colspan="4" width="250" height="250" nolabel="1"/>
</page>
<page string="Body (Rich/HTML)">
<field name="body_html" colspan="4" nolabel="1"/>
<field name="body_html" colspan="4" width="250" height="250" nolabel="1"/>
<label string="Note: This is Raw HTML." colspan="4"/>
</page>
</notebook>

View File

@ -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)

View File

@ -8,26 +8,31 @@
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Email Preview">
<group col="4" colspan="4">
<field name="model_id" readonly="1"/>
<field name="res_id" on_change="on_change_ref(res_id, context)"/>
</group>
<group col="8" colspan="4">
<field name="model_id" invisible="1"/>
<field name="res_id" on_change="on_change_res_id(res_id, context)"/>
<group col="2" colspan="4">
<field name="email_to" readonly="1"/>
<field name="email_cc" readonly="1"/>
<field name="email_bcc" readonly="1"/>
<field name="reply_to" readonly="1"/>
<field name="subject" colspan="8" readonly="1"/>
<field name="email_cc" readonly="1" attrs="{'invisible': [('email_cc','=',False)]}"/>
<field name="email_bcc" readonly="1" attrs="{'invisible': [('email_bcc','=',False)]}"/>
<field name="reply_to" readonly="1" attrs="{'invisible': [('reply_to','=',False)]}"/>
<field name="subject" readonly="1"/>
</group>
<group col="4" colspan="4">
<separator string= "Body" colspan="2" />
<!--<separator string= "Body(Html)" colspan="2" />-->
<newline/>
<field name="body_text" nolabel="1" colspan="2" readonly="1"/>
<!-- <field name="body_html" nolabel="1" colspan="2" readonly="1"/>-->
<notebook>
<page string="Body (Text)">
<field name="body_text" nolabel="1" colspan="4" height="350" width="350" readonly="1"/>
</page>
<page string="Body (Rich/HTML)" attrs="{'invisible': [('body_html','=', False)]}">
<field name="body_html" nolabel="1" colspan="4" height="350" width="350" readonly="1"/>
</page>
</notebook>
</group>
<field name="report_name" colspan="4" readonly="1"/>
<separator colspan="4"/>
<group col="4" colspan="4">
<label string=""/>
<button icon="gtk-ok" special="cancel" string="Close" colspan="1"/>
</group>
<field name="report_name" colspan="2" readonly="1"/>
<button icon="gtk-ok" special="cancel" string="OK" colspan="1"/>
</form>
</field>
</record>

View File

@ -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)
}