[IMP]: email_template:
*able to save email as new template to reuse it *evaluating expression type for mail same as email_template bzr revid: rha@tinyerp.com-20110426115445-qpx91w218tyg4jde
This commit is contained in:
parent
f5fab68157
commit
d63731b65f
|
@ -152,10 +152,6 @@ class email_template(osv.osv):
|
|||
'body_html': fields.text('HTML', help="Contains HTML version of email. Placeholders can be used here."),
|
||||
}
|
||||
|
||||
_sql_constraints = [
|
||||
('name', 'unique (name)','The template name must be unique !')
|
||||
]
|
||||
|
||||
def create_action(self, cr, uid, ids, context=None):
|
||||
vals = {}
|
||||
if context is None:
|
||||
|
|
|
@ -79,6 +79,33 @@ class email_compose_message(osv.osv_memory):
|
|||
values['attachment_ids'] = att_ids
|
||||
return {'value': values}
|
||||
|
||||
def save_as_new_template(self, cr, uid, ids, context=None):
|
||||
'''
|
||||
create a new template record
|
||||
'''
|
||||
if context is None:
|
||||
context = {}
|
||||
template_pool = self.pool.get('email.template')
|
||||
model_pool = self.pool.get('ir.model')
|
||||
for record in self.browse(cr, uid, ids, context=context):
|
||||
model = model_pool.search(cr, uid, [('name','=', record.model)])[0]
|
||||
values = {
|
||||
'name': record.model,
|
||||
'email_from': record.email_from or False,
|
||||
'subject': record.subject or False,
|
||||
'body': record.body or False,
|
||||
'email_to': record.email_to or False,
|
||||
'email_cc': record.email_cc or False,
|
||||
'email_bcc': record.email_bcc or False,
|
||||
'reply_to': record.reply_to or False,
|
||||
'auto_delete': record.auto_delete,
|
||||
'model_id': model or False,
|
||||
'smtp_server_id': record.smtp_server_id.id or False,
|
||||
'attachment_ids': [(6, 0, [att.id for att in record.attachment_ids])]
|
||||
}
|
||||
template_pool.create(cr, uid, values, context=context)
|
||||
return True
|
||||
|
||||
email_compose_message()
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
|
|
@ -8,10 +8,15 @@
|
|||
<field name="type">form</field>
|
||||
<field name="inherit_id" ref="mail.email_compose_message_wizard_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="model" position="after">
|
||||
<field name="template_id" colspan="4"
|
||||
<data>
|
||||
<xpath expr="//field[@name='model']" position="after">
|
||||
<field name="template_id" colspan="4"
|
||||
on_change="on_change_template(template_id, context)"/>
|
||||
</field>
|
||||
</xpath>
|
||||
<xpath expr="//button[@string='Close']" position="after">
|
||||
<button icon="" type="object" name="save_as_new_template" string="Save As New Template"/>
|
||||
</xpath>
|
||||
</data>
|
||||
</field>
|
||||
</record>
|
||||
</data>
|
||||
|
|
|
@ -225,7 +225,7 @@ class email_compose_message(osv.osv_memory):
|
|||
if context is None:
|
||||
context = {}
|
||||
def merge(match):
|
||||
exp = str(match.group()[2:-2]).strip()
|
||||
exp = str(match.group()[2:-1]).strip()
|
||||
result = eval(exp,
|
||||
{
|
||||
'user' : self.pool.get('res.users').browse(cr, uid, uid, context=context),
|
||||
|
@ -236,7 +236,7 @@ class email_compose_message(osv.osv_memory):
|
|||
return str("--------")
|
||||
return tools.ustr(result)
|
||||
|
||||
com = re.compile('(\[\[.+?\]\])')
|
||||
com = re.compile('(\$\{.+?\})')
|
||||
return message and com.sub(merge, message)
|
||||
|
||||
email_compose_message()
|
||||
|
|
Loading…
Reference in New Issue