[IMP]: CRM email integration Improvement
Generate client side email threats for each case bzr revid: mga@tinyerp.com-20100415154220-8xuzn32det2jd4oo
This commit is contained in:
+5
-15
@@ -501,20 +501,7 @@ class crm_case(osv.osv):
|
||||
self.write(cr, uid, [case.id], {'stage_id': s[section][st]})
|
||||
return True
|
||||
|
||||
def history(self, cr, uid, ids, keyword, history=False, email=False, details=None, context={}):
|
||||
"""
|
||||
@param self: The object pointer
|
||||
@param cr: the current row, from the database cursor,
|
||||
@param uid: the current user’s ID for security checks,
|
||||
@param ids: List of History’s IDs
|
||||
@param context: A standard dictionary for contextual values"""
|
||||
|
||||
cases = self.browse(cr, uid, ids, context=context)
|
||||
return self.__history(cr, uid, cases, keyword=keyword, \
|
||||
history=history, email=email, details=details, \
|
||||
context=context)
|
||||
|
||||
def __history(self, cr, uid, cases, keyword, history=False, email=False, details=None, email_from=False, context={}):
|
||||
def __history(self, cr, uid, cases, keyword, history=False, email=False, details=None, email_from=False, message_id=False, context={}):
|
||||
"""
|
||||
@param self: The object pointer
|
||||
@param cr: the current row, from the database cursor,
|
||||
@@ -533,7 +520,8 @@ class crm_case(osv.osv):
|
||||
'date': time.strftime('%Y-%m-%d %H:%M:%S'),
|
||||
'model_id' : model_ids and model_ids[0] or False,
|
||||
'res_id': case.id,
|
||||
'section_id': case.section_id.id
|
||||
'section_id': case.section_id.id,
|
||||
'message_id':message_id
|
||||
}
|
||||
|
||||
obj = self.pool.get('crm.case.log')
|
||||
@@ -551,6 +539,7 @@ class crm_case(osv.osv):
|
||||
res = obj.create(cr, uid, data, context)
|
||||
return True
|
||||
_history = __history
|
||||
history = __history
|
||||
|
||||
def create(self, cr, uid, *args, **argv):
|
||||
|
||||
@@ -849,6 +838,7 @@ class crm_case_history(osv.osv):
|
||||
'email_to': fields.char('Email TO', size=84),
|
||||
'email_from' : fields.char('Email From', size=84),
|
||||
'log_id': fields.many2one('crm.case.log','Log',ondelete='cascade'),
|
||||
'message_id': fields.char('Message Id', size=1024, readonly=True, help="Message Id on Email Server.", select=True),
|
||||
}
|
||||
|
||||
crm_case_history()
|
||||
|
||||
+61
-58
@@ -38,81 +38,84 @@ class crm_cases(osv.osv):
|
||||
_name = "crm.case"
|
||||
_inherit = "crm.case"
|
||||
|
||||
def msg_new(self, cr, uid, msg):
|
||||
|
||||
""" @param self: The object pointer
|
||||
@param cr: the current row, from the database cursor,
|
||||
@param uid: the current user’s ID for security checks
|
||||
def message_new(self, cr, uid, msg, context):
|
||||
"""
|
||||
Automatically calls when new email message arrives
|
||||
|
||||
@param self: The object pointer
|
||||
@param cr: the current row, from the database cursor,
|
||||
@param uid: the current user’s ID for security checks
|
||||
"""
|
||||
|
||||
mailgate_obj = self.pool.get('mail.gateway')
|
||||
msg_body = mailgate_obj.msg_body_get(msg)
|
||||
msg_subject = mailgate_obj._decode_header(msg['Subject'])
|
||||
msg_from = mailgate_obj._decode_header(msg['From'])
|
||||
msg_cc = mailgate_obj._decode_header(msg['Cc'])
|
||||
body = self.format_body(msg_body['body'])
|
||||
data = {
|
||||
'name': msg_subject,
|
||||
mailgate_pool = self.pool.get('email.server.tools')
|
||||
|
||||
subject = msg.get('subject')
|
||||
body = msg.get('body')
|
||||
msg_from = msg.get('from')
|
||||
priority = msg.get('priority')
|
||||
|
||||
vals = {
|
||||
'name': subject,
|
||||
'email_from': msg_from,
|
||||
'email_cc': msg_cc,
|
||||
'email_cc': msg.get('cc'),
|
||||
'description': body,
|
||||
'user_id': False,
|
||||
'description': body,
|
||||
}
|
||||
res = mailgate_obj.partner_get(cr, uid, msg_from)
|
||||
if msg.get('priority', False):
|
||||
vals['priority'] = priority
|
||||
|
||||
res = mailgate_pool.get_partner(cr, uid, msg.get('from'))
|
||||
if res:
|
||||
data.update(res)
|
||||
res = self.create(cr, uid, data)
|
||||
cases = self.browse(cr, uid, [res])
|
||||
self._history(cr, uid, cases, _('Receive'), history=True, details=body, email_from=msg_from)
|
||||
vals.update(res)
|
||||
res = self.create(cr, uid, vals, context)
|
||||
cases = self.browse(cr, uid, [res])
|
||||
self._history(cr, uid, cases, _('Receive'), history=True, details=body, email_from=msg_from, message_id=msg.get('id'))
|
||||
return res
|
||||
|
||||
def msg_update(self, cr, uid, ids, msg, data={}, default_act='pending'):
|
||||
|
||||
""" @param self: The object pointer
|
||||
@param cr: the current row, from the database cursor,
|
||||
@param uid: the current user’s ID for security checks,
|
||||
@param ids: List of update mail’s IDs """
|
||||
|
||||
def message_update(self, cr, uid, ids, msg, default_act='pending', context={}):
|
||||
"""
|
||||
@param self: The object pointer
|
||||
@param cr: the current row, from the database cursor,
|
||||
@param uid: the current user’s ID for security checks,
|
||||
@param ids: List of update mail’s IDs
|
||||
"""
|
||||
|
||||
vals = { }
|
||||
if isinstance(ids, (str, int, long)):
|
||||
select = [ids]
|
||||
else:
|
||||
select = ids
|
||||
mailgate_obj = self.pool.get('mail.gateway')
|
||||
msg_actions, body_data = mailgate_obj.msg_act_get(msg)
|
||||
data.update({
|
||||
'description': body_data,
|
||||
ids = [ids]
|
||||
|
||||
msg_from = msg['from']
|
||||
vals.update({
|
||||
'description': msg['body']
|
||||
})
|
||||
act = 'case_'+default_act
|
||||
if 'state' in msg_actions:
|
||||
if msg_actions['state'] in ['draft','close','cancel','open','pending']:
|
||||
act = 'case_' + msg_actions['state']
|
||||
if msg.get('priority', False):
|
||||
vals['priority'] = msg.get('priority')
|
||||
|
||||
for k1,k2 in [('cost','planned_cost'),('revenue','planned_revenue'),('probability','probability')]:
|
||||
if k1 in msg_actions:
|
||||
data[k2] = float(msg_actions[k1])
|
||||
# act = 'case_'+default_act
|
||||
# if 'state' in msg_actions:
|
||||
# if msg_actions['state'] in ['draft','close','cancel','open','pending']:
|
||||
# act = 'case_' + msg_actions['state']
|
||||
|
||||
if 'priority' in msg_actions:
|
||||
if msg_actions['priority'] in ('1','2','3','4','5'):
|
||||
data['priority'] = msg_actions['priority']
|
||||
# for k1,k2 in [('cost','planned_cost'),('revenue','planned_revenue'),('probability','probability')]:
|
||||
# if k1 in msg_actions:
|
||||
# data[k2] = float(msg_actions[k1])
|
||||
|
||||
if 'partner' in msg_actions:
|
||||
data['email_from'] = msg_actions['partner'][:128]
|
||||
msg_from = self._decode_header(msg['From'])
|
||||
res = self.write(cr, uid, select, data)
|
||||
cases = self.browse(cr, uid, select)
|
||||
self._history(cr, uid, cases, _('Receive'), history=True, details=body_data, email_from=msg['From'])
|
||||
getattr(self,act)(cr, uid, select)
|
||||
res = self.write(cr, uid, ids, vals)
|
||||
cases = self.browse(cr, uid, ids)
|
||||
message_id = context.get('message_id', False)
|
||||
self._history(cr, uid, cases, _('Receive'), history=True, details=msg['body'], email_from=msg_from, message_id=message_id)
|
||||
#getattr(self, act)(cr, uid, select)
|
||||
return res
|
||||
|
||||
def emails_get(self, cr, uid, ids, context={}):
|
||||
|
||||
""" Get Emails
|
||||
@param self: The object pointer
|
||||
@param cr: the current row, from the database cursor,
|
||||
@param uid: the current user’s ID for security checks,
|
||||
@param ids: List of email’s IDs
|
||||
@param context: A standard dictionary for contextual values
|
||||
|
||||
"""
|
||||
Get Emails
|
||||
@param self: The object pointer
|
||||
@param cr: the current row, from the database cursor,
|
||||
@param uid: the current user’s ID for security checks,
|
||||
@param ids: List of email’s IDs
|
||||
@param context: A standard dictionary for contextual values
|
||||
"""
|
||||
res = []
|
||||
if isinstance(ids, (str, int, long)):
|
||||
|
||||
@@ -71,10 +71,14 @@ class crm_send_new_email(osv.osv_memory):
|
||||
attach = filter(lambda x: x, [data['doc1'], data['doc2'], data['doc3']])
|
||||
attach = map(lambda x: x and ('Attachment'+str(attach.index(x)+1), base64.decodestring(x)), attach)
|
||||
|
||||
message_id = None
|
||||
|
||||
if context.get('mail', 'new') == 'new':
|
||||
case = case_pool.browse(cr, uid, res_id)
|
||||
message_id = case.history_line[0].message_id
|
||||
else:
|
||||
hist = hist_obj.browse(cr, uid, res_id)
|
||||
message_id = hist.message_id
|
||||
model = hist.log_id.model_id.model
|
||||
model_pool = self.pool.get(model)
|
||||
case = model_pool.browse(cr, uid, hist.log_id.res_id)
|
||||
@@ -84,7 +88,11 @@ class crm_send_new_email(osv.osv_memory):
|
||||
|
||||
body = case_pool.format_body(body)
|
||||
email_from = data.get('email_from', False)
|
||||
case_pool._history(cr, uid, [case], _('Send'), history=True, email=data['email_to'], details=body, email_from=email_from)
|
||||
case_pool._history(cr, uid, [case], _('Send'), history=True, email=data['email_to'], details=body, email_from=email_from, message_id=message_id)
|
||||
|
||||
x_headers = {
|
||||
'References':"%s" % (message_id)
|
||||
}
|
||||
|
||||
flag = tools.email_send(
|
||||
email_from,
|
||||
@@ -94,6 +102,7 @@ class crm_send_new_email(osv.osv_memory):
|
||||
attach=attach,
|
||||
reply_to=case.section_id.reply_to,
|
||||
openobject_id=str(case.id),
|
||||
x_headers=x_headers
|
||||
)
|
||||
if flag:
|
||||
if data['state'] == 'unchanged':
|
||||
@@ -111,7 +120,7 @@ class crm_send_new_email(osv.osv_memory):
|
||||
# raise osv.except_osv(_('Email!'), ("Email Successfully Sent"))
|
||||
# else:
|
||||
# raise osv.except_osv(_('Warning!'), _("Email not sent !"))
|
||||
|
||||
|
||||
return {}
|
||||
|
||||
def default_get(self, cr, uid, fields, context=None):
|
||||
|
||||
Reference in New Issue
Block a user