[IMP] emails :- improve default value of email.message.send wizard. crm :- call email.message.send wizard of emails module instead of crm module wizard

bzr revid: ysa@tinyerp.com-20110218102748-8x7kaztiadm52h0n
This commit is contained in:
Yogesh (OpenERP) 2011-02-18 15:57:48 +05:30
parent 7065eebae3
commit f4ff6da00e
5 changed files with 97 additions and 63 deletions

View File

@ -288,6 +288,37 @@ class crm_lead(crm_case, osv.osv):
}
return value
def action_send_email(self, cr, uid, ids, context=None):
"""
Open Send email wizard.
"""
if context is None:
context = {}
for lead in self.browse(cr, uid ,ids, context):
context.update({
'mail':'new',
'model': 'crm.lead',
'default_name': lead.name,
'default_email_to': lead.email_from,
'default_email_from': lead.user_id and lead.user_id.address_id and lead.user_id.address_id.email,
'default_description': '\n' + (tools.ustr(lead.user_id.signature or '')),
'default_reply_to': lead.section_id and lead.section_id.reply_to or False,
'default_model': context.get('model',''),
'default_email_cc': tools.ustr(lead.email_cc or ''),
'default_res_id': context.get('rec_id',0)
})
result = {
'view_type': 'form',
'view_mode': 'form',
'res_model': 'email.message.wizard_send',
'view_id': False,
'context': context,
'type': 'ir.actions.act_window',
'target': 'new',
'nodestroy': True
}
return result
def write(self, cr, uid, ids, vals, context=None):
if not context:
context = {}

View File

@ -13,8 +13,8 @@
<field name="context">{'type':'lead'}</field>
<field name="help">Add specific stages to leads and opportunities allowing your sales to better organise their sales pipeline. Stages will allow them to easily track how a specific lead or opportunity is positioned in the sales cycle.</field>
</record>
<menuitem action="crm_lead_stage_act" id="menu_crm_lead_stage_act" name="Stages"
groups="base.group_extended" sequence="0"
@ -170,8 +170,8 @@
<field name="history" invisible="1"/>
<button
string="Reply" attrs="{'invisible': [('history', '!=', True)]}"
name="%(crm.action_crm_send_mail)d"
context="{'mail':'reply', 'model': 'crm.lead', 'include_original' : True}"
name="%(emails.action_email_message_wizard_send)d"
context="{'mail':'reply', 'model': 'crm.lead', 'include_original' : True, 'message_id':active_id}"
icon="terp-mail-replied" type="action" />
</tree>
<form string="Communication history">
@ -189,8 +189,8 @@
<field name="description" colspan="4" nolabel="1" height="250"/>
<button colspan="4"
string="Reply"
name="%(crm.action_crm_send_mail)d"
context="{'mail':'reply', 'model': 'crm.lead', 'include_original' : True}"
name="%(emails.action_email_message_wizard_send)d"
context="{'mail':'reply', 'model': 'crm.lead', 'include_original' : True, 'message_id':active_id}"
icon="terp-mail-replied" type="action" />
</group>
<group attrs="{'invisible': [('history', '=', True)]}">
@ -208,9 +208,9 @@
context="{'model': 'crm.lead' }"
icon="terp-document-new" type="action" />
<button string="Send New Email"
name="%(crm.action_crm_send_mail)d"
context="{'mail':'new', 'model': 'crm.lead'}"
icon="terp-mail-message-new" type="action" />
name="action_send_email"
context="{'mail':'new', 'model': 'crm.lead', 'rec_id' : active_id}"
icon="terp-mail-message-new" type="object" />
</page>
</notebook>
</form>

View File

@ -31,10 +31,11 @@
<separator string="Message Details" colspan="4"/>
<field name="model" readonly="1"/>
<group col="3" colspan="2">
<field name="res_id" readonly="1"/>
<field name="res_id" readonly="1"/>
<button name="open_document" string="Open Document" type="object" icon="gtk-jump-to"/>
<field name="message_id"/>
<button name="%(action_email_message_wizard_send)d" string="Reply" type="action" icon="terp-mail-replied"/>
<button name="%(action_email_message_wizard_send)d" string="Reply" type="action" icon="terp-mail-replied"
context="{'mail':'reply', 'message_id':active_id}"/>
</group>
</group>
<separator string="Description" colspan="4"/>

View File

@ -37,76 +37,79 @@ class email_message_wizard_send(osv.osv_memory):
model_pool = self.pool.get('ir.model')
message_id = context.get('message_id', False)
message_data = None
message_data = False
if message_id:
message_data = message_pool.browse(cr, uid, message_id, context)
message_data = message_pool.browse(cr, uid, int(message_id), context)
if 'template_id' in fields:
result['template_id'] = message_data and message_data.template_id and message_data.template_id.id or False
if 'template_id' in fields:
result['template_id'] = context.get('default_template_id',False) or (message_data and message_data.template_id and message_data.template_id.id or False)
if 'smtp_server_id' in fields:
result['smtp_server_id'] = message_data and message_data.smtp_server_id and message_data.smtp_server_id.id or False
if 'smtp_server_id' in fields:
result['smtp_server_id'] = context.get('default_smtp_server_id',False) or (message_data and message_data.smtp_server_id and message_data.smtp_server_id.id or False)
if 'message_id' in fields:
result['message_id'] = message_data and message_data.message_id
if 'message_id' in fields:
result['message_id'] = context.get('default_message_id','') or (message_data and message_data.message_id)
if 'attachment_ids' in fields:
result['attachment_ids'] = message_data and message_pool.read(cr, uid, message_id, ['attachment_ids'])['attachment_ids']
if 'attachment_ids' in fields:
result['attachment_ids'] = context.get('default_attachment_ids',[]) or (message_data and message_pool.read(cr, uid, message_id, ['attachment_ids'])['attachment_ids'])
if 'res_id' in fields:
result['res_id'] = message_data and message_data.res_id
if 'res_id' in fields:
result['res_id'] = context.get('default_res_id',0) or (message_data and message_data.res_id)
if 'email_from' in fields:
result['email_from'] = message_data and message_data.email_from
if 'email_from' in fields:
result['email_from'] = context.get('default_email_from','') or (message_data and message_data.email_from)
if 'email_to' in fields:
result['email_to'] = message_data and message_data.email_to
if 'email_to' in fields:
result['email_to'] = context.get('default_email_to','') or (message_data and message_data.email_to)
if 'email_cc' in fields:
result['email_cc'] = message_data and message_data.email_cc
if 'email_cc' in fields:
result['email_cc'] = context.get('default_email_cc', '') or (message_data and message_data.email_cc)
if 'email_bcc' in fields:
result['email_bcc'] = message_data and message_data.email_bcc
if 'email_bcc' in fields:
result['email_bcc'] = context.get('default_email_bcc', '') or (message_data and message_data.email_bcc)
if 'name' in fields:
result['name'] = tools.ustr(message_data and message_data.name or '')
if context.get('mail','') == 'reply':
result['name'] = "Re :- " + result['name']
if 'name' in fields:
result['name'] = "Re : " + tools.ustr(context.get('default_name', '') or (message_data and message_data.name))
if 'description' in fields:
description = message_data and message_data.description and message_data.description or ''
if context.get('mail','') == 'reply':
header = '-------- Original Message --------'
sender = 'From: %s' % tools.ustr(message_data.email_from or '')
email_to = 'To: %s' % tools.ustr(message_data.email_to or '')
sentdate = 'Date: %s' % message_data.date
desc = '\n > \t %s' % tools.ustr(description.replace('\n', "\n > \t") or '')
result['description'] = '\n'.join([header, sender, email_to, sentdate, desc])
else:
result['description'] = description
if 'description' in fields:
description = context.get('default_description', '') or (message_data and message_data.description and message_data.description or '')
header = '-------- Original Message --------'
sender = 'From: %s' % tools.ustr(message_data.email_from or '')
email_to = 'To: %s' % tools.ustr(message_data.email_to or '')
sentdate = 'Date: %s' % message_data.date
desc = '\n > \t %s' % tools.ustr(description.replace('\n', "\n > \t") or '')
original = [header, sender, email_to, sentdate, desc]
result['description'] = '\n'.join(original)
if 'reply_to' in fields:
result['reply_to'] = message_data and message_data.reply_to
if 'reply_to' in fields:
result['reply_to'] = context.get('default_reply_to', '') or (message_data and message_data.reply_to)
if 'model' in fields:
result['model'] = message_data and message_data.model
if 'model' in fields:
result['model'] = context.get('default_model', '') or (message_data and message_data.model)
if 'user_id' in fields:
result['user_id'] = message_data and message_data.user_id and message_data.user_id.id or False
if 'user_id' in fields:
result['user_id'] = context.get('default_user_id', False) or (message_data and message_data.user_id and message_data.user_id.id or False)
if 'references' in fields:
result['references'] = tools.ustr(message_data and message_data.references)
if 'references' in fields:
result['references'] = tools.ustr(context.get('default_references', '') or (message_data and message_data.references))
if 'sub_type' in fields:
result['sub_type'] = message_data and message_data.sub_type
if 'sub_type' in fields:
result['sub_type'] = context.get('default_sub_type') or (message_data and message_data.sub_type)
if 'headers' in fields:
result['headers'] = message_data and message_data.headers
if 'headers' in fields:
result['headers'] = context.get('default_headers', {}) or (message_data and message_data.headers)
if 'priority' in fields:
result['priority'] = message_data and message_data.priority
if 'priority' in fields:
result['priority'] = context.get('default_priority') or (message_data and message_data.priority)
if 'partner_id' in fields:
result['partner_id'] = message_data and message_data.partner_id and message_data.partner_id.id or False
if 'partner_id' in fields:
result['partner_id'] = context.get('default_partner_id', False) or (message_data and message_data.partner_id and message_data.partner_id.id or False)
if 'debug' in fields:
result['debug'] = context.get('default_debug', False) or (message_data and message_data.debug)
if 'debug' in fields:
result['debug'] = message_data and message_data.debug
return result

View File

@ -36,7 +36,6 @@
</field>
</record>
<record id="action_email_message_wizard_send" model="ir.actions.act_window">
<field name="name">Send E-mail</field>
<field name="res_model">email.message.wizard_send</field>
@ -45,7 +44,7 @@
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
<field name="context">{'message_id':active_id}</field>
<field name="context">{'message_id':active_id, 'mail':'reply'}</field>
</record>
</data>