[IMP]: crm: Code improvement in forward to partner wizard
bzr revid: rpa@tinyerp.com-20100715112425-7w3t8rtbsdkbbqc1
This commit is contained in:
@@ -21,7 +21,6 @@
|
||||
##############################################################################
|
||||
|
||||
import base64
|
||||
import itertools
|
||||
import time
|
||||
import re
|
||||
from osv import osv, fields
|
||||
@@ -165,63 +164,25 @@ class crm_lead_forward_to_partner(osv.osv_memory):
|
||||
email = self.pool.get('res.partner.address').browse(cr, uid, address_id).email
|
||||
return {'value': {'email_to' : email}}
|
||||
|
||||
def action_cancel(self, cr, uid, ids, context=None):
|
||||
return {'type' : 'ir.actions.act_window_close'}
|
||||
|
||||
def action_forward(self, cr, uid, ids, context=None):
|
||||
"""
|
||||
Forward the lead to a partner
|
||||
"""
|
||||
if context is None:
|
||||
context = {}
|
||||
|
||||
res_id = context.get('active_id', False)
|
||||
|
||||
model = context.get('active_model', False)
|
||||
if not res_id or not model:
|
||||
return {}
|
||||
|
||||
email_re = r'([^ ,<@]+@[^> ,]+)'
|
||||
|
||||
this = self.browse(cr, uid, ids[0], context=context)
|
||||
|
||||
case_pool = self.pool.get(model)
|
||||
case_pool = self.pool.get(context.get('active_model'))
|
||||
res_id = context and context.get('active_id', False) or False
|
||||
case = case_pool.browse(cr, uid, res_id, context=context)
|
||||
|
||||
emails = [this.email_to]
|
||||
body = case_pool.format_body(this.body)
|
||||
email_from = this.email_from or False
|
||||
context.update({'mail': 'forward'})
|
||||
super(crm_lead_forward_to_partner, self).action_send(cr, uid, ids, context=context)
|
||||
|
||||
# extract attachements from case and emails according to mode
|
||||
attachments = []
|
||||
attach_pool = self.pool.get('ir.attachment')
|
||||
direct_attachments = attach_pool.search(cr, uid, [('res_model', '=', 'crm.lead'), ('res_id', '=', res_id)], context=context)
|
||||
attachments += attach_pool.browse(cr, uid, direct_attachments, context=context)
|
||||
if this.history in ['latest', 'whole'] and case.message_ids:
|
||||
msgs = case.message_ids
|
||||
if this.history == 'latest':
|
||||
msgs = msgs[:1]
|
||||
attachments.extend(itertools.chain(*[m.attachment_ids for m in msgs]))
|
||||
attach = [(a.datas_fname or a.name, base64.decodestring(a.datas)) for a in attachments if a.datas]
|
||||
|
||||
result = tools.email_send(
|
||||
email_from,
|
||||
emails,
|
||||
this.subject,
|
||||
body,
|
||||
openobject_id=str(case.id),
|
||||
attach=attach,
|
||||
reply_to=case.section_id.reply_to,
|
||||
)
|
||||
|
||||
if result:
|
||||
case_pool.history(cr, uid, [case], _('Forward'), history=True, email=this.email_to, subject=this.subject, details=body, email_from=email_from, attach=attach)
|
||||
to_write = {'date_assign': time.strftime('%Y-%m-%d')}
|
||||
if (this.name == 'partner' and this.partner_id):
|
||||
to_write['partner_assigned_id'] = this.partner_id.id
|
||||
case_pool.write(cr, uid, case.id, to_write)
|
||||
else:
|
||||
raise osv.except_osv(_('Error!'), _('Unable to send mail. Please check SMTP is configured properly.'))
|
||||
to_write = {'date_assign': time.strftime('%Y-%m-%d')}
|
||||
if (this.name == 'partner' and this.partner_id):
|
||||
to_write['partner_assigned_id'] = this.partner_id.id
|
||||
case_pool.write(cr, uid, case.id, to_write)
|
||||
|
||||
email_re = r'([^ ,<@]+@[^> ,]+)'
|
||||
email_cc = re.findall(email_re, case.email_cc or '')
|
||||
new_cc = ''
|
||||
for to in this.email_to.split(','):
|
||||
|
||||
@@ -20,11 +20,12 @@
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from crm import crm
|
||||
from osv import osv, fields
|
||||
from tools.translate import _
|
||||
import base64
|
||||
import itertools
|
||||
import tools
|
||||
from crm import crm
|
||||
|
||||
class crm_send_new_email_attachment(osv.osv_memory):
|
||||
_name = 'crm.send.mail.attachment'
|
||||
@@ -54,15 +55,9 @@ class crm_send_new_email(osv.osv_memory):
|
||||
'attachment_ids' : fields.one2many('crm.send.mail.attachment', 'wizard_id'),
|
||||
}
|
||||
|
||||
def action_cancel(self, cr, uid, ids, context=None):
|
||||
""" Closes Phonecall to Opportunity form
|
||||
"""
|
||||
return {'type':'ir.actions.act_window_close'}
|
||||
|
||||
def action_send(self, cr, uid, ids, context=None):
|
||||
""" This sends an email to ALL the addresses of the selected partners.
|
||||
"""
|
||||
|
||||
hist_obj = self.pool.get('mailgate.message')
|
||||
|
||||
if not context:
|
||||
@@ -83,18 +78,32 @@ class crm_send_new_email(osv.osv_memory):
|
||||
message_id = None
|
||||
ref_id = None
|
||||
|
||||
case = case_pool.browse(cr, uid, res_id)
|
||||
case = case_pool.browse(cr, uid, res_id, context=context)
|
||||
if context.get('mail', 'new') == 'new':
|
||||
if case.message_ids:
|
||||
message_id = case.message_ids[0].message_id
|
||||
elif context.get('mail') == 'forward':
|
||||
# extract attachements from case and emails according to mode
|
||||
attachments = []
|
||||
attach_pool = self.pool.get('ir.attachment')
|
||||
direct_attachments = attach_pool.search(cr, uid, [('res_model', '=', 'crm.lead'), ('res_id', '=', res_id)], context=context)
|
||||
attachments += attach_pool.browse(cr, uid, direct_attachments, context=context)
|
||||
if obj.history in ['latest', 'whole'] and case.message_ids:
|
||||
msgs = case.message_ids
|
||||
if obj.history == 'latest':
|
||||
msgs = msgs[:1]
|
||||
attachments.extend(itertools.chain(*[m.attachment_ids for m in msgs]))
|
||||
attach_all = [(a.datas_fname or a.name, base64.decodestring(a.datas)) for a in attachments if a.datas]
|
||||
attach += attach_all
|
||||
|
||||
else:
|
||||
hist = hist_obj.browse(cr, uid, res_id)
|
||||
hist = hist_obj.browse(cr, uid, res_id, context=context)
|
||||
message_id = hist.message_id
|
||||
model = hist.model
|
||||
case_pool = self.pool.get(model)
|
||||
res_id = hist.res_id
|
||||
ref_id = hist.ref_id
|
||||
case = case_pool.browse(cr, uid, res_id)
|
||||
case = case_pool.browse(cr, uid, res_id, context=context)
|
||||
emails = [obj.email_to]
|
||||
email_cc = obj.email_cc and obj.email_cc.split(',') or ''
|
||||
emails = filter(None, emails)
|
||||
@@ -121,7 +130,8 @@ class crm_send_new_email(osv.osv_memory):
|
||||
if not flag:
|
||||
raise osv.except_osv(_('Error!'), _('Unable to send mail. Please check SMTP is configured properly.'))
|
||||
|
||||
case_pool.history(cr, uid, [case], _('Send'), history=True, \
|
||||
msg_dict = {'new': 'Send', 'reply': 'Reply', 'forward': 'Forward'}
|
||||
case_pool.history(cr, uid, [case], _(msg_dict[context.get('mail', 'new')]), history=True, \
|
||||
email=obj.email_to, details=body, \
|
||||
subject=obj.subject, email_from=email_from, \
|
||||
email_cc=', '.join(email_cc), message_id=message_id, \
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
<separator string="" colspan="6"/>
|
||||
<group colspan="6" col="4" >
|
||||
<field name="state" />
|
||||
<button name="action_cancel" string="_Cancel" icon="gtk-cancel" special="cancel" />
|
||||
<button string="_Cancel" icon="gtk-cancel" special="cancel" />
|
||||
<button name="action_send" type="object" string="_Send" icon="gtk-go-forward" />
|
||||
</group>
|
||||
</form>
|
||||
|
||||
Reference in New Issue
Block a user