[MERGE] [IMP] email_template: template_id field is now a many2one towards email.template

- changed selection field to a many2one using a domain; this
allows to edit the template while being in a composition wizard.
- improved email template and template preview form view

bzr revid: tde@openerp.com-20130329114631-fd6phvjaxojk9ja5
This commit is contained in:
Thibault Delavallée 2013-03-29 12:46:31 +01:00
commit 0d14fd300a
10 changed files with 73 additions and 68 deletions

View File

@ -421,6 +421,7 @@ class account_invoice(osv.osv):
'mark_invoice_as_sent': True,
})
return {
'name': _('Compose Email'),
'type': 'ir.actions.act_window',
'view_type': 'form',
'view_mode': 'form',

View File

@ -944,6 +944,7 @@ class crm_lead(base_stage, format_address, osv.osv):
'default_composition_mode': 'comment',
})
return {
'name': _('Compose Email'),
'type': 'ir.actions.act_window',
'view_type': 'form',
'view_mode': 'form',

View File

@ -228,7 +228,7 @@
<field name="name">Lead/Opportunity Mass Mail</field>
<field name="model_id" ref="crm.model_crm_lead"/>
<field name="auto_delete" eval="True"/>
<field name="partner_to">${object.partner_id and object.partner_id.id}</field>
<field name="partner_to">${object.partner_id != False and object.partner_id.id}</field>
<field name="email_to">${not object.partner_id and object.email_from}</field>
<field name="body_html"></field>
</record>

View File

@ -9,7 +9,7 @@
<sheet>
<div class="oe_title">
<label for="name" class="oe_edit_only"/><h1><field name="name" required="1"/></h1>
<h3><label for="model_id"/><field name="model_id" required="1" on_change="onchange_model_id(model_id)" class="oe_inline"/></h3>
<label for="model_id"/><field name="model_id" required="1" on_change="onchange_model_id(model_id)" class="oe_inline"/>
<field name="model" invisible="1"/>
</div>
<div class="oe_right oe_button_box" name="buttons">
@ -25,30 +25,44 @@
context="{'template_id':active_id}"/>
</div>
<notebook>
<page string="Email Details">
<page string="Mailing Template">
<group>
<group string="Addressing">
<field name="email_from"/>
<field name="email_to"/>
<field name="partner_to"/>
<field name="email_cc"/>
<field name="reply_to"/>
<field name="user_signature"/>
<group>
<field name="email_from"
placeholder="Override author's email"/>
<field name="email_to"
placeholder="Comma-separated recipient addresses"/>
<field name="partner_to"
placeholder="Comma-separated ids of recipient partners"/>
<field name="email_cc"
placeholder="Comma-separated carbon copy recipients addresses"/>
<field name="reply_to"
placeholder="Preferred reply address"/>
<field name="subject"
placeholder="Subject (placeholders may be used here)"/>
<field name="user_signature" string="Author Signature (mass mail only)"/>
</group>
<group string="Dynamic Value Builder" class="oe_edit_only">
<field name="model_object_field" domain="[('model_id','=',model_id),('ttype','!=','one2many'),('ttype','!=','many2many')]" on_change="onchange_sub_model_object_value_field(model_object_field)"/>
<field name="sub_object" readonly="1"/>
<field name="sub_model_object_field" domain="[('model_id','=',sub_object),('ttype','!=','one2many'),('ttype','!=','many2many')]" attrs="{'readonly':[('sub_object','=',False)],'required':[('sub_object','!=',False)]}" on_change="onchange_sub_model_object_value_field(model_object_field,sub_model_object_field)"/>
<field name="null_value" on_change="onchange_sub_model_object_value_field(model_object_field,sub_model_object_field,null_value)"/>
<field name="copyvalue"/>
</group>
<group string="Contents" colspan="2">
<field name="subject"/>
<field name="body_html" width="250" height="450" nolabel="1" colspan="2" placeholder="Email contents (in raw HTML format)"/>
<group class="oe_edit_only">
<h3 colspan="2">Dynamic placeholder generator</h3>
<field name="model_object_field"
domain="[('model_id','=',model_id),('ttype','!=','one2many'),('ttype','!=','many2many')]"
on_change="onchange_sub_model_object_value_field(model_object_field)"/>
<field name="sub_object" readonly="1"/>
<field name="sub_model_object_field"
domain="[('model_id','=',sub_object),('ttype','!=','one2many'),('ttype','!=','many2many')]"
attrs="{'readonly':[('sub_object','=',False)],'required':[('sub_object','!=',False)]}"
on_change="onchange_sub_model_object_value_field(model_object_field,sub_model_object_field)"/>
<field name="null_value"
on_change="onchange_sub_model_object_value_field(model_object_field,sub_model_object_field,null_value)"/>
<field name="copyvalue"/>
</group>
</group>
<h3>Body</h3>
<field name="body_html" width="250" height="450"
placeholder="Rich-text/HTML content of the message (placeholders may be used here)"/>
<field name="attachment_ids" nolabel="1" widget="many2many_binary"/>
</page>
<page string="Advanced">
<page string="Advanced Settings">
<group>
<field name="lang"/>
<field name="mail_server_id"/>
@ -56,9 +70,6 @@
<field name="report_template" domain="[('model','=',model)]"/>
<field name="report_name" class="oe_inline"
attrs="{'invisible':[('report_template','=',False)]}"/>
<field name="attachment_ids">
<tree><field name="name"/></tree>
</field>
</group>
</page>
</notebook>

View File

@ -69,15 +69,19 @@ class email_template_preview(osv.osv_memory):
}
def on_change_res_id(self, cr, uid, ids, res_id, context=None):
if not res_id: return {}
vals = {}
if context is None:
context = {'value': {}}
if not res_id or not context.get('template_id'):
return {'value': {}}
email_template = self.pool.get('email.template')
template_id = context and context.get('template_id')
template_id = context.get('template_id')
template = email_template.browse(cr, uid, template_id, context=context)
vals['name'] = template.name
# generate and get template values
mail_values = email_template.generate_email(cr, uid, template_id, res_id, context=context)
for k in ('email_from','email_to','email_cc','reply_to','subject','body_html'):
vals[k] = mail_values[k]
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['name'] = template.name
return {'value': vals}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -7,22 +7,22 @@
<field name="model">email_template.preview</field>
<field name="arch" type="xml">
<form string="Email Preview" version="7.0">
<div>
<h2>Preview of <field name="name" readonly="1" class="oe_inline"/></h2>
<field name="model_id" invisible="1"/>
<h3>Using sample document
<field name="res_id" on_change="on_change_res_id(res_id, context)" class="oe_inline"/>
</h3>
</div>
<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"/>
<group>
<field name="email_from" readonly="1"/>
<field name="email_to" readonly="1"/>
<field name="partner_to" 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"/>
<field name="body_html" widget="html" readonly="1" options='{"safe": True}'/>
<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="email_cc" readonly="1"
attrs="{'invisible':[('email_cc','=',False)]}"/>
<field name="reply_to" readonly="1"
attrs="{'invisible':[('reply_to','=',False)]}"/>
</group>
<field name="body_html" widget="html" readonly="1"
nolabel="1" options='{"safe": True}'/>
</form>
</field>
</record>

View File

@ -39,26 +39,8 @@ def _reopen(self, res_id, model):
class mail_compose_message(osv.TransientModel):
_inherit = 'mail.compose.message'
def _get_templates(self, cr, uid, context=None):
if context is None:
context = {}
model = False
email_template_obj = self.pool.get('email.template')
message_id = context.get('default_parent_id', context.get('message_id', context.get('active_id')))
if context.get('default_composition_mode') == 'reply' and message_id:
message_data = self.pool.get('mail.message').browse(cr, uid, message_id, context=context)
if message_data:
model = message_data.model
else:
model = context.get('default_model', context.get('active_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, '')]
_columns = {
# incredible hack of the day: size=-1 means we want an int db column instead of an str one
'template_id': fields.selection(_get_templates, 'Template', size=-1),
'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)',
@ -114,10 +96,13 @@ class mail_compose_message(osv.TransientModel):
'subject': record.subject or False,
'body_html': record.body or False,
'model_id': model_id or False,
'attachment_ids': [(6, 0, [att.id for att in record.attachment_ids])]
'attachment_ids': [(6, 0, [att.id for att in record.attachment_ids])],
}
template_id = email_template.create(cr, uid, values, context=context)
record.write(record.onchange_template_id(template_id, record.composition_mode, record.model, record.res_id)['value'])
# generate the saved template
template_values = record.onchange_template_id(template_id, record.composition_mode, record.model, record.res_id)['value']
template_values['template_id'] = template_id
record.write(template_values)
return _reopen(self, record.id, record.model)
#------------------------------------------------------

View File

@ -24,10 +24,11 @@
</div>
</xpath>
<xpath expr="//footer" position="inside">
<group class="oe_right" col="1">
<group class="oe_right oe_form" col="1">
<div>Use template
<field name="template_id" nolabel="1"
on_change="onchange_template_id(template_id, composition_mode, model, res_id, context)"/>
<!--FIX: To avoid css issue of many2one field in footer temporary used oe_form (BUG:1152464)-->
<field name="template_id" nolabel="1" class='oe_inline'
on_change="onchange_template_id(template_id, composition_mode, model, res_id, context)" domain="[('model_id','=',context.get('default_model'))]"/>
</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"

View File

@ -1934,6 +1934,7 @@ openerp.mail = function (session) {
this.$(".oe_write_full").click(function (event) {
event.stopPropagation();
var action = {
name: _t('Compose Email'),
type: 'ir.actions.act_window',
res_model: 'mail.compose.message',
view_mode: 'form',

View File

@ -426,6 +426,7 @@ class purchase_order(osv.osv):
'default_composition_mode': 'comment',
})
return {
'name': _('Compose Email'),
'type': 'ir.actions.act_window',
'view_type': 'form',
'view_mode': 'form',