[IMP] email_template :- Change the action of old email.send wizard to new email.compose.message in create_action method in email_template and inherit default_get method and set default value of template.
bzr revid: ysa@tinyerp.com-20110224104801-xcua49za83sm12mn
This commit is contained in:
parent
ece864e532
commit
122e28da04
|
@ -183,15 +183,15 @@ This is useful for CRM leads for example"),
|
|||
data_obj = self.pool.get('ir.model.data')
|
||||
for template in self.browse(cr, uid, ids, context=context):
|
||||
src_obj = template.model_id.model
|
||||
model_data_id = data_obj._get_id(cr, uid, 'email_template', 'email_template_send_wizard_form')
|
||||
model_data_id = data_obj._get_id(cr, uid, 'emails', 'email_compose_message_wizard_form')
|
||||
res_id = data_obj.browse(cr, uid, model_data_id, context=context).res_id
|
||||
vals['ref_ir_act_window'] = action_obj.create(cr, uid, {
|
||||
'name': template.name,
|
||||
'type': 'ir.actions.act_window',
|
||||
'res_model': 'email_template.send.wizard',
|
||||
'res_model': 'email.compose.message',
|
||||
'src_model': src_obj,
|
||||
'view_type': 'form',
|
||||
'context': "{'src_model':'%s','template_id':'%d','src_rec_id':active_id,'src_rec_ids':active_ids}" % (src_obj, template.id),
|
||||
'context': "{'email_model':'%s','template_id':'%d','src_rec_id':active_id,'src_rec_ids':active_ids}" % (src_obj, template.id),
|
||||
'view_mode':'form,tree',
|
||||
'view_id': res_id,
|
||||
'target': 'new',
|
||||
|
|
|
@ -26,6 +26,57 @@ import tools
|
|||
class email_compose_message(osv.osv_memory):
|
||||
_name = 'email.compose.message'
|
||||
_inherit = 'email.compose.message'
|
||||
def default_get(self, cr, uid, fields, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
result = super(email_compose_message, self).default_get(cr, uid, fields, context=context)
|
||||
template_pool = self.pool.get('email.template')
|
||||
model_pool = self.pool.get('ir.model')
|
||||
template_id = context.get('template_id', False)
|
||||
if template_id:
|
||||
template = template_pool.get_email_template(cr, uid, template_id=template_id, context=context)
|
||||
def _get_template_value(field):
|
||||
if not template:
|
||||
return False
|
||||
if len(context['src_rec_ids']) > 1: # Multiple Mail: Gets original template values for multiple email change
|
||||
return getattr(template, field)
|
||||
else: # Simple Mail: Gets computed template values
|
||||
return template_pool.get_template_value(cr, uid, getattr(template, field), template.model, context.get('active_id'), context)
|
||||
|
||||
if 'template_id' in fields:
|
||||
result['template_id'] = template.id
|
||||
|
||||
if 'smtp_server_id' in fields:
|
||||
result['smtp_server_id'] = template.smtp_server_id.id
|
||||
|
||||
if 'attachment_ids' in fields:
|
||||
result['attachment_ids'] = template_pool.read(cr, uid, template.id, ['attachment_ids'])['attachment_ids']
|
||||
|
||||
if 'model' in fields:
|
||||
result['model'] = context.get('email_model')
|
||||
|
||||
if 'res_id' in fields:
|
||||
result['res_id'] = context.get('active_id')
|
||||
|
||||
if 'email_to' in fields:
|
||||
result['email_to'] = _get_template_value('email_to')
|
||||
|
||||
if 'email_cc' in fields:
|
||||
result['email_cc'] = _get_template_value('email_cc')
|
||||
|
||||
if 'email_bcc' in fields:
|
||||
result['email_bcc'] = _get_template_value('email_bcc')
|
||||
|
||||
if 'name' in fields:
|
||||
result['name'] = _get_template_value('subject')
|
||||
|
||||
if 'description' in fields:
|
||||
result['description'] = _get_template_value('description')
|
||||
|
||||
if 'reply_to' in fields:
|
||||
result['reply_to'] = _get_template_value('reply_to')
|
||||
|
||||
return result
|
||||
|
||||
def _get_templates(self, cr, uid, context=None):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue