[IMP] improce email.compose wizard code. and change active_id to email_res_id.
bzr revid: ysa@tinyerp.com-20110301095057-sb8tsgovwpt852yj
This commit is contained in:
commit
230b03e26f
|
@ -108,7 +108,7 @@
|
|||
<field name="email_from" widget="email"/>
|
||||
<button string="Send Email"
|
||||
name="%(emails.action_email_compose_message_wizard)d"
|
||||
context="{'email_model':'crm.lead'}"
|
||||
context="{'email_model':'crm.lead', 'email_res_id': active_id}"
|
||||
icon="terp-mail-message-new" type="action" colspan="1"/>
|
||||
<newline/>
|
||||
<field name="phone"/>
|
||||
|
@ -227,7 +227,7 @@
|
|||
icon="terp-document-new" type="action" />
|
||||
<button string="Send New Email"
|
||||
name="%(emails.action_email_compose_message_wizard)d"
|
||||
context="{'email_model':'crm.lead'}"
|
||||
context="{'email_model':'crm.lead', 'email_res_id': active_id}"
|
||||
icon="terp-mail-message-new" type="action"/>
|
||||
</page>
|
||||
</notebook>
|
||||
|
|
|
@ -61,7 +61,7 @@
|
|||
<field name="email_from" string="Email" />
|
||||
<button string="Send Email"
|
||||
name="%(emails.action_email_compose_message_wizard)d"
|
||||
context="{'email_model': 'crm.lead'}"
|
||||
context="{'email_model': 'crm.lead', 'email_res_id': active_id}"
|
||||
icon="terp-mail-message-new" type="action"/>
|
||||
</group>
|
||||
<field name="phone"/>
|
||||
|
@ -183,7 +183,7 @@
|
|||
icon="terp-document-new" type="action" />
|
||||
<button string="Send New Email"
|
||||
name="%(emails.action_email_compose_message_wizard)d"
|
||||
context="{'email_model': 'crm.lead'}"
|
||||
context="{'email_model': 'crm.lead', 'email_res_id': active_id}"
|
||||
icon="terp-mail-message-new" type="action"/>
|
||||
</page>
|
||||
<page string="Extra Info" groups="base.group_extended">
|
||||
|
|
|
@ -38,13 +38,13 @@ class email_compose_message(osv.osv_memory):
|
|||
model_obj = self.pool.get(model)
|
||||
data = model_obj.browse(cr, uid , resource_id, context)
|
||||
result.update({
|
||||
'name' : data.name,
|
||||
'email_to' : data.email_from,
|
||||
'name' : data.name or False,
|
||||
'email_to' : data.email_from or False,
|
||||
'email_from' : data.user_id and data.user_id.address_id and data.user_id.address_id.email or False,
|
||||
'description' : '\n' + (tools.ustr(data.user_id.signature or '')),
|
||||
'email_cc' : tools.ustr(data.email_cc or ''),
|
||||
'model': model,
|
||||
'res_id': resource_id,
|
||||
'model': model or False,
|
||||
'res_id': resource_id or False,
|
||||
})
|
||||
if hasattr(data, 'section_id'):
|
||||
result.update({'reply_to' : data.section_id and data.section_id.reply_to or False})
|
||||
|
|
|
@ -215,7 +215,7 @@
|
|||
icon="terp-document-new" type="action" />
|
||||
<button string="Send New Email"
|
||||
name="%(emails.action_email_compose_message_wizard)d"
|
||||
context="{'email_model':'crm.claim'}"
|
||||
context="{'email_model':'crm.claim', 'email_res_id': active_id}"
|
||||
icon="terp-mail-message-new" type="action"/>
|
||||
</page>
|
||||
</notebook>
|
||||
|
|
|
@ -206,7 +206,7 @@
|
|||
icon="terp-document-new" type="action" />
|
||||
<button string="Send New Email"
|
||||
name="%(emails.action_email_compose_message_wizard)d"
|
||||
context="{'email_model':'crm.fundraising'}"
|
||||
context="{'email_model':'crm.fundraising', 'email_res_id': active_id}"
|
||||
icon="terp-mail-message-new" type="action"/>
|
||||
</page>
|
||||
<page string="Extra Info" groups="base.group_extended">
|
||||
|
|
|
@ -140,7 +140,7 @@
|
|||
icon="terp-document-new" type="action" />
|
||||
<button string="Send New Email"
|
||||
name="%(emails.action_email_compose_message_wizard)d"
|
||||
context="{'email_model':'crm.helpdesk'}"
|
||||
context="{'email_model':'crm.helpdesk', 'email_res_id': active_id}"
|
||||
icon="terp-mail-message-new" type="action"/>
|
||||
</page>
|
||||
<page string="Extra Info" groups="base.group_extended">
|
||||
|
|
|
@ -191,7 +191,7 @@ This is useful for CRM leads for example"),
|
|||
'res_model': 'email.compose.message',
|
||||
'src_model': src_obj,
|
||||
'view_type': 'form',
|
||||
'context': "{'email_model':'%s','template_id':'%d','src_rec_id':active_id,'src_rec_ids':active_ids}" % (src_obj, template.id),
|
||||
'context': "{'email_model':'%s', 'email_res_id': active_id,'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',
|
||||
|
|
|
@ -41,7 +41,7 @@ class email_compose_message(osv.osv_memory):
|
|||
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)
|
||||
return template_pool.get_template_value(cr, uid, getattr(template, field), template.model, context.get('email_res_id'), context)
|
||||
|
||||
if 'template_id' in fields:
|
||||
result['template_id'] = template.id
|
||||
|
@ -56,7 +56,7 @@ class email_compose_message(osv.osv_memory):
|
|||
result['model'] = context.get('email_model')
|
||||
|
||||
if 'res_id' in fields:
|
||||
result['res_id'] = context.get('active_id')
|
||||
result['res_id'] = context.get('email_res_id')
|
||||
|
||||
if 'email_to' in fields:
|
||||
result['email_to'] = _get_template_value('email_to')
|
||||
|
|
|
@ -32,100 +32,67 @@ class email_compose_message(osv.osv_memory):
|
|||
if context is None:
|
||||
context = {}
|
||||
result = super(email_compose_message, self).default_get(cr, uid, fields, context=context)
|
||||
if context.get('email_model') and context.get('active_id'):
|
||||
vals = self.get_value(cr, uid, context.get('email_model'), context.get('active_id'), context)
|
||||
if 'name' in fields and vals:
|
||||
result.update({'name' : vals.get('name','')})
|
||||
vals = {}
|
||||
if context.get('email_model') and context.get('email_res_id'):
|
||||
vals = self.get_value(cr, uid, context.get('email_model'), context.get('email_res_id'), context)
|
||||
elif context.get('message_id', False):
|
||||
vals = self.get_message_data(cr, uid, int(context.get('message_id', False)), context)
|
||||
else:
|
||||
result['model'] = context.get('email_model', False)
|
||||
|
||||
if 'email_to' in fields and vals:
|
||||
result.update({'email_to' : vals.get('email_to','')})
|
||||
if not vals:
|
||||
return result
|
||||
|
||||
if 'email_from' in fields and vals:
|
||||
result.update({'email_from' : vals.get('email_from','')})
|
||||
if 'name' in fields:
|
||||
result.update({'name' : vals.get('name','')})
|
||||
|
||||
if 'description' in fields and vals:
|
||||
result.update({'description' : vals.get('description','')})
|
||||
if 'email_to' in fields:
|
||||
result.update({'email_to' : vals.get('email_to','')})
|
||||
|
||||
if 'model' in fields and vals:
|
||||
result.update({'model' : vals.get('model','')})
|
||||
if 'email_from' in fields:
|
||||
result.update({'email_from' : vals.get('email_from','')})
|
||||
|
||||
if 'email_cc' in fields and vals:
|
||||
result.update({'email_cc' : vals.get('email_cc','')})
|
||||
if 'description' in fields:
|
||||
result.update({'description' : vals.get('description','')})
|
||||
|
||||
if 'res_id' in fields and vals:
|
||||
result.update({'res_id' : vals.get('res_id',0)})
|
||||
if 'model' in fields:
|
||||
result.update({'model' : vals.get('model','')})
|
||||
|
||||
if 'reply_to' in fields and vals:
|
||||
result['reply_to'] = vals.get('reply_to','')
|
||||
if 'email_cc' in fields:
|
||||
result.update({'email_cc' : vals.get('email_cc','')})
|
||||
|
||||
message_pool = self.pool.get('email.message')
|
||||
message_id = context.get('message_id', False)
|
||||
if message_id:
|
||||
message_data = message_pool.browse(cr, uid, int(message_id), context)
|
||||
if 'message_id' in fields:
|
||||
result['message_id'] = message_data and message_data.message_id
|
||||
if 'email_bcc' in fields:
|
||||
result.update({'email_bcc' : vals.get('email_bcc','')})
|
||||
|
||||
if 'attachment_ids' in fields:
|
||||
result['attachment_ids'] = message_data and message_pool.read(cr, uid, message_id, ['attachment_ids'])['attachment_ids']
|
||||
if 'res_id' in fields:
|
||||
result.update({'res_id' : vals.get('res_id',0)})
|
||||
|
||||
if 'res_id' in fields:
|
||||
result['res_id'] = message_data and message_data.res_id
|
||||
if 'reply_to' in fields:
|
||||
result['reply_to'] = vals.get('reply_to','')
|
||||
|
||||
if 'email_from' in fields:
|
||||
result['email_from'] = message_data and message_data.email_to
|
||||
if 'message_id' in fields:
|
||||
result['message_id'] = vals.get('message_id','')
|
||||
|
||||
if 'email_to' in fields:
|
||||
result['email_to'] = message_data and message_data.email_from
|
||||
if 'attachment_ids' in fields:
|
||||
result['attachment_ids'] = vals.get('attachment_ids',[])
|
||||
|
||||
if 'email_cc' in fields:
|
||||
result['email_cc'] = message_data and message_data.email_cc
|
||||
if 'user_id' in fields:
|
||||
result['user_id'] = vals.get('user_id',False)
|
||||
|
||||
if 'email_bcc' in fields:
|
||||
result['email_bcc'] = message_data and message_data.email_bcc
|
||||
if 'references' in fields:
|
||||
result['references'] = vals.get('references',False)
|
||||
|
||||
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 'sub_type' in fields:
|
||||
result['sub_type'] = vals.get('sub_type',False)
|
||||
|
||||
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 'headers' in fields:
|
||||
result['headers'] = vals.get('headers',False)
|
||||
|
||||
if 'reply_to' in fields:
|
||||
result['reply_to'] = message_data and message_data.reply_to
|
||||
if 'priority' in fields:
|
||||
result['priority'] = vals.get('priority',False)
|
||||
|
||||
if 'model' in fields:
|
||||
result['model'] = 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 'references' in fields:
|
||||
result['references'] = message_data and message_data.references and tools.ustr(message_data.references)
|
||||
|
||||
if 'sub_type' in fields:
|
||||
result['sub_type'] = message_data and message_data.sub_type
|
||||
|
||||
if 'headers' in fields:
|
||||
result['headers'] = message_data and message_data.headers
|
||||
|
||||
if 'priority' in fields:
|
||||
result['priority'] = message_data and message_data.priority
|
||||
|
||||
if 'debug' in fields:
|
||||
result['debug'] = message_data and message_data.debug
|
||||
|
||||
if 'model' in fields and context.get('email_model',False):
|
||||
result['model'] = context.get('email_model')
|
||||
if 'debug' in fields:
|
||||
result['debug'] = vals.get('debug',False)
|
||||
|
||||
return result
|
||||
|
||||
|
@ -145,7 +112,7 @@ class email_compose_message(osv.osv_memory):
|
|||
elif context.get('email_model',False):
|
||||
model = context.get('email_model')
|
||||
model_pool = self.pool.get(model)
|
||||
record_ids = context.get('active_ids',[])
|
||||
record_ids = context.get('email_res_id') and [context.get('email_res_id')] or []
|
||||
if not record_ids:
|
||||
record_ids = model_pool.search(cr, uid, [])
|
||||
if model_pool:
|
||||
|
@ -158,9 +125,52 @@ class email_compose_message(osv.osv_memory):
|
|||
'res_id':fields.selection(_get_records, 'Referred Document'),
|
||||
}
|
||||
|
||||
def get_value(self, cr, uid, model, resource_id, context=None):
|
||||
def get_value(self, cr, uid, model, res_id, context=None):
|
||||
return {}
|
||||
|
||||
def get_message_data(self, cr, uid, message_id, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
result = {}
|
||||
message_pool = self.pool.get('email.message')
|
||||
if message_id:
|
||||
message_data = message_pool.browse(cr, uid, message_id, context)
|
||||
subject = tools.ustr(message_data and message_data.name or '')
|
||||
if context.get('mail','') == 'reply':
|
||||
subject = "Re :- " + subject
|
||||
|
||||
description = message_data and message_data.description and message_data.description or ''
|
||||
message_body = False
|
||||
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 '')
|
||||
description = '\n'.join([header, sender, email_to, sentdate, desc])
|
||||
|
||||
result.update({
|
||||
'description' : description,
|
||||
'name' : subject,
|
||||
'message_id' : message_data and message_data.message_id or False,
|
||||
'attachment_ids' : message_data and message_pool.read(cr, uid, message_id, ['attachment_ids'])['attachment_ids'] or [],
|
||||
'res_id' : message_data and message_data.res_id or False,
|
||||
'email_from' : message_data and message_data.email_to or False,
|
||||
'email_to' : message_data and message_data.email_from or False,
|
||||
'email_cc' : message_data and message_data.email_cc or False,
|
||||
'email_bcc' : message_data and message_data.email_bcc or False,
|
||||
'reply_to' : message_data and message_data.reply_to or False,
|
||||
'model' : message_data and message_data.model or False,
|
||||
'user_id' : message_data and message_data.user_id and message_data.user_id.id or False,
|
||||
'references' : message_data and message_data.references and tools.ustr(message_data.references) or False,
|
||||
'sub_type' : message_data and message_data.sub_type or False,
|
||||
'headers' : message_data and message_data.headers or False,
|
||||
'priority' : message_data and message_data.priority or False,
|
||||
'debug': message_data and message_data.debug or False
|
||||
})
|
||||
|
||||
return result
|
||||
|
||||
def on_change_referred_doc(self, cr, uid, ids, model, resource_id, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
|
|
|
@ -431,7 +431,7 @@
|
|||
icon="terp-document-new" type="action" />
|
||||
<button string="Send New Email"
|
||||
name="%(emails.action_email_compose_message_wizard)d"
|
||||
context="{'email_model':'event.registration'}"
|
||||
context="{'email_model':'event.registration', 'email_res_id': active_id}"
|
||||
icon="terp-mail-message-new" type="action"/>
|
||||
</page>
|
||||
</notebook>
|
||||
|
|
|
@ -27,14 +27,6 @@ from tools.translate import _
|
|||
class email_compose_message(osv.osv_memory):
|
||||
_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)
|
||||
if context.get('email_model',False) and context.get('email_model') == 'hr.evaluation.interview' and 'model' in fields:
|
||||
result['model'] = context.get('email_model','')
|
||||
return result
|
||||
|
||||
def _get_records(self, cr, uid, context=None):
|
||||
"""
|
||||
Return Records of particular Model
|
||||
|
@ -53,31 +45,25 @@ class email_compose_message(osv.osv_memory):
|
|||
'res_id':fields.selection(_get_records, 'Referred Document'),
|
||||
}
|
||||
|
||||
def on_change_referred_doc(self, cr, uid, ids, model, resource_id, context=None):
|
||||
def get_value(self, cr, uid, model, resource_id, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
if context.get('mail') == 'reply':
|
||||
return {'value':{}}
|
||||
result = super(email_compose_message, self).on_change_referred_doc(cr, uid, ids, model, resource_id, context=context)
|
||||
value = {}
|
||||
if not result.get('value'):
|
||||
result.update({'value':{}})
|
||||
|
||||
result = super(email_compose_message, self).get_value(cr, uid, model, resource_id, context=context)
|
||||
if model == 'hr.evaluation.interview' and resource_id:
|
||||
model_pool = self.pool.get(model)
|
||||
record_data = model_pool.browse(cr, uid, resource_id, context)
|
||||
if record_data.state == "waiting_answer":
|
||||
msg = _("Hello %s, \n\n Kindly post your response for '%s' survey interview. \n\n Thanks,") %(record_data.user_to_review_id.name, record_data.survey_id.title)
|
||||
result['value'].update({
|
||||
'email_from': tools.config.get('email_from',''),
|
||||
'email_to': record_data.user_to_review_id.work_email or False,
|
||||
'name': _("Reminder to fill up Survey"),
|
||||
'description': msg,
|
||||
'res_id': resource_id,
|
||||
'email_cc': False,
|
||||
'email_bcc': False,
|
||||
'reply_to': False,
|
||||
})
|
||||
result.update({
|
||||
'email_from': tools.config.get('email_from',''),
|
||||
'email_to': record_data.user_to_review_id.work_email or False,
|
||||
'name': _("Reminder to fill up Survey"),
|
||||
'description': msg,
|
||||
'res_id': resource_id,
|
||||
'email_cc': False,
|
||||
'email_bcc': False,
|
||||
'reply_to': False,
|
||||
})
|
||||
return result
|
||||
|
||||
email_compose_message()
|
||||
|
|
|
@ -185,7 +185,7 @@
|
|||
icon="terp-document-new" type="action" />
|
||||
<button string="Send New Email"
|
||||
name="%(emails.action_email_compose_message_wizard)d"
|
||||
context="{'email_model': 'hr.applicant'}"
|
||||
context="{'email_model': 'hr.applicant', 'email_res_id': active_id}"
|
||||
icon="terp-mail-message-new" type="action"/>
|
||||
</page>
|
||||
<page string="Notes">
|
||||
|
|
|
@ -51,7 +51,7 @@ class email_compose_message(osv.osv_memory):
|
|||
header = (task_data.project_id.warn_header or '') % val
|
||||
footer = (task_data.project_id.warn_footer or '') % val
|
||||
description = u'%s\n %s\n %s\n\n \n%s' % (header, task_data.description or '', footer, task_data.user_id and task_data.user_id.signature)
|
||||
if partner and len(partner.address) and 'email_to' in fields:
|
||||
if partner and len(partner.address):
|
||||
result.update({'email_to': result.get('email_to',False) and result.get('email_to') + ',' + partner.address[0].email})
|
||||
result.update({
|
||||
'description': description or False,
|
||||
|
|
|
@ -142,7 +142,7 @@
|
|||
icon="terp-document-new" type="action" />
|
||||
<button string="Send New Email"
|
||||
name="%(emails.action_email_compose_message_wizard)d"
|
||||
context="{'email_model':'project.issue'}"
|
||||
context="{'email_model':'project.issue', 'email_res_id': active_id}"
|
||||
icon="terp-mail-message-new" type="action"/>
|
||||
</page>
|
||||
<page string="Extra Info" groups="base.group_extended">
|
||||
|
|
|
@ -109,7 +109,7 @@
|
|||
<button name="do_reopen" states="done,cancelled" string="Reactivate" type="object" icon="gtk-convert"/>
|
||||
<button name="do_pending" states="open" string="Pending" type="object" icon="gtk-media-pause"/>
|
||||
<button groups="base.group_extended" name="%(project.action_project_task_delegate)d" states="pending,open" string="Delegate" type="action" icon="gtk-sort-descending"/>
|
||||
<button name="%(emails.action_email_compose_message_wizard)d" context="{'email_model':'project.task'}" states="pending,open" string="Done" type="action" icon="gtk-jump-to"/>
|
||||
<button name="%(emails.action_email_compose_message_wizard)d" context="{'email_model':'project.task', 'email_res_id': active_id}" states="pending,open" string="Done" type="action" icon="gtk-jump-to"/>
|
||||
</group>
|
||||
</page>
|
||||
<page groups="base.group_extended" string="Extra Info" attrs="{'readonly':[('state','=','done')]}">
|
||||
|
|
|
@ -396,7 +396,7 @@
|
|||
<field name="user_id"/>
|
||||
<button name="%(emails.action_email_compose_message_wizard)d"
|
||||
string="Send Email" type="action" icon="terp-mail-message-new"
|
||||
context="{'email_model': 'project.scrum.meeting'}"/>
|
||||
context="{'email_model': 'project.scrum.meeting', 'email_res_id': active_id}"/>
|
||||
</group>
|
||||
<notebook colspan="4">
|
||||
<page string="Scrum Meeting">
|
||||
|
|
Loading…
Reference in New Issue