[IMP]: crm: History must create only if mail is sent successfully
[IMP]: crm: Subject should be prefixed by "Re: " when reply to last mail [FIX]: crm: email is sent to email ids of email_cc field but it was going as TO instead of CC bzr revid: rpa@tinyerp.com-20100624130307-mt11m89tuvopiz7i
This commit is contained in:
@@ -183,14 +183,18 @@ class crm_lead_forward_to_partner(osv.osv_memory):
|
||||
emails = [this.email_to]
|
||||
body = case_pool.format_body(this.message)
|
||||
email_from = this.email_from or False
|
||||
case_pool._history(cr, uid, [case], _('Forward'), history=True, email=this.email_to, details=body, email_from=email_from)
|
||||
|
||||
flag = False
|
||||
flag = tools.email_send(
|
||||
email_from,
|
||||
emails,
|
||||
this.subject,
|
||||
body,
|
||||
)
|
||||
if flag:
|
||||
case_pool._history(cr, uid, [case], _('Forward'), history=True, email=this.email_to, subject=this.subject, details=body, email_from=email_from)
|
||||
if not flag:
|
||||
raise osv.except_osv(_('Error!'), _('Unable to send mail. Please check SMTP is configured properly.'))
|
||||
if this.add_cc:
|
||||
case_pool.write(cr, uid, case.id, {'email_cc' : case.email_cc and case.email_cc + ', ' + this.email_to or this.email_to})
|
||||
return {}
|
||||
@@ -199,7 +203,7 @@ class crm_lead_forward_to_partner(osv.osv_memory):
|
||||
message = []
|
||||
lead_proxy = self.pool.get('crm.lead')
|
||||
lead = lead_proxy.browse(cr, uid, lead_id, context=context)
|
||||
if lead.type == 'lead':
|
||||
if not lead.type or lead.type == 'lead':
|
||||
field_names = [
|
||||
'partner_name', 'title', 'function', 'street', 'street2',
|
||||
'zip', 'city', 'country_id', 'state_id', 'email_from',
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
from osv import osv, fields
|
||||
from tools.translate import _
|
||||
import base64
|
||||
import time
|
||||
import tools
|
||||
from crm import crm
|
||||
|
||||
@@ -96,42 +97,46 @@ class crm_send_new_email(osv.osv_memory):
|
||||
else:
|
||||
hist = hist_obj.browse(cr, uid, res_id)
|
||||
message_id = hist.message_id
|
||||
model = hist.res_model
|
||||
model = hist.model
|
||||
model_pool = self.pool.get(model)
|
||||
case = model_pool.browse(cr, uid, hist.res_id)
|
||||
res_id = hist.res_id
|
||||
emails = [obj.email_to] + (obj.email_cc or '').split(',')
|
||||
res_ids = model_pool.search(cr, uid, [('thread_id','=', hist.thread_id.id)])
|
||||
res_id = res_ids and res_ids[0] or False
|
||||
case = model_pool.browse(cr, uid, res_id)
|
||||
emails = [obj.email_to]
|
||||
email_cc = (obj.email_cc or '').split(',')
|
||||
emails = filter(None, emails)
|
||||
body = obj.text
|
||||
|
||||
body = case_pool.format_body(body)
|
||||
email_from = getattr(obj, 'email_from', False)
|
||||
|
||||
case_pool._history(cr, uid, [case], _('Send'), history=True, \
|
||||
email=obj.email_to, details=body, \
|
||||
subject=obj.subject, email_from=email_from, \
|
||||
message_id=message_id, attach=attach)
|
||||
|
||||
x_headers = dict()
|
||||
#x_headers = {
|
||||
# 'Reply-To':"%s" % case.section_id.reply_to,
|
||||
#}
|
||||
x_headers = {
|
||||
'model': model,
|
||||
'resource-id': res_id
|
||||
}
|
||||
if message_id:
|
||||
x_headers['References'] = "%s" % (message_id)
|
||||
|
||||
print case.section_id
|
||||
flag = False
|
||||
|
||||
flag = tools.email_send(
|
||||
email_from,
|
||||
emails,
|
||||
obj.subject,
|
||||
body,
|
||||
email_cc=email_cc,
|
||||
attach=attach,
|
||||
reply_to=case.section_id and case.section_id.reply_to or email_from,
|
||||
openobject_id=str(case.id),
|
||||
x_headers=x_headers
|
||||
)
|
||||
|
||||
if not flag:
|
||||
raise osv.except_osv(_('Error!'), _('Unable to send mail. Please check SMTP is configured properly.'))
|
||||
if flag:
|
||||
case_pool._history(cr, uid, [case], _('Send'), history=True, \
|
||||
email=obj.email_to, details=body, \
|
||||
subject=obj.subject, email_from=email_from, \
|
||||
message_id=message_id, attach=attach)
|
||||
if obj.state == 'unchanged':
|
||||
pass
|
||||
elif obj.state == 'done':
|
||||
@@ -194,14 +199,15 @@ class crm_send_new_email(osv.osv_memory):
|
||||
include_original = context and context.get('include_original', False) or False
|
||||
res = {}
|
||||
for hist in hist_obj.browse(cr, uid, res_ids, context=context):
|
||||
model = hist.res_model
|
||||
model = hist.model
|
||||
|
||||
# In the case where the crm.case does not exist in the database
|
||||
if not model:
|
||||
return {}
|
||||
|
||||
model_pool = self.pool.get(model)
|
||||
res_id = hist.res_id or False
|
||||
res_ids = model_pool.search(cr, uid, [('thread_id','=', hist.thread_id.id)])
|
||||
res_id = res_ids and res_ids[0] or False
|
||||
case = model_pool.browse(cr, uid, res_id)
|
||||
if 'email_to' in fields:
|
||||
res.update({'email_to': case.email_from or hist.email_from or False})
|
||||
@@ -222,10 +228,10 @@ class crm_send_new_email(osv.osv_memory):
|
||||
|
||||
original = [header, sender, to, sentdate, desc, signature]
|
||||
|
||||
res['text']= '\n'.join(original)
|
||||
res['text']= '\n\n\n' + '\n'.join(original)
|
||||
|
||||
if 'subject' in fields:
|
||||
res.update({'subject': '[%s] %s' %(str(case.id), case.name or '')})
|
||||
res.update({'subject': 'Re: %s' %(hist.name or '')})
|
||||
if 'state' in fields:
|
||||
res['state']='pending'
|
||||
return res
|
||||
|
||||
Reference in New Issue
Block a user