summaryrefslogtreecommitdiff
path: root/addons/plugin/plugin_handler.py
diff options
context:
space:
mode:
authorRaphael Collet <rco@openerp.com>2012-02-03 14:39:47 +0100
committerRaphael Collet <rco@openerp.com>2012-02-03 14:39:47 +0100
commit3af06d4c3feb2ece795485620c3a87554b446238 (patch)
tree220bfe52446f48367f47431ec908186f44715255 /addons/plugin/plugin_handler.py
parentb839539b83dcc7f2eee9f4885186a64f6fe4e056 (diff)
parent6ae335382cb669fd3b49a3bc71eb118066c2de4a (diff)
[MERGE] from trunk
bzr revid: rco@openerp.com-20120203133947-ev7o3vz28k39261m
Diffstat (limited to 'addons/plugin/plugin_handler.py')
-rw-r--r--addons/plugin/plugin_handler.py60
1 files changed, 36 insertions, 24 deletions
diff --git a/addons/plugin/plugin_handler.py b/addons/plugin/plugin_handler.py
index c4859771e35..ef990170e64 100644
--- a/addons/plugin/plugin_handler.py
+++ b/addons/plugin/plugin_handler.py
@@ -12,13 +12,14 @@ class plugin_handler(osv.osv_memory):
def _make_url(self, cr, uid, res_id, model, context=None):
"""
- @param id: on which document the message is pushed
+ @param res_id: on which document the message is pushed
@param model: name of the document linked with the mail
@return url
"""
base_url = self.pool.get('ir.config_parameter').get_param(cr, uid, 'web.base.url', default='http://localhost:8069', context=context)
if base_url:
- base_url += '/?id=%s&model=%s'%(res_id,model)
+ user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
+ base_url += '/web/webclient/login?db=%s&login=%s&key=%s#id=%s&model=%s' % (cr.dbname, user.login, user.password, res_id, model)
return base_url
def is_installed(self, cr, uid):
@@ -35,28 +36,27 @@ class plugin_handler(osv.osv_memory):
@param email: email is a standard RFC2822 email message
@return Dictionary which contain id and the model name of the document linked with the mail
if no document is found the id = 0
- (model_name, res_id, name_get, url)
+ (model_name, res_id, url, name_get)
"""
mail_message_obj = self.pool.get('mail.message')
- model = False
+ model = ""
res_id = 0
- url = False
+ url = ""
name = ""
-
msg = mail_message_obj.parse_message(email)
references = [msg.get('message-id')]
refs = msg.get('references',False)
if refs:
references.extend(refs.split())
-
msg_ids = mail_message_obj.search(cr, uid, [('message_id','in',references)])
if msg_ids:
msg = mail_message_obj.browse(cr, uid, msg_ids[0])
res_id = msg.res_id
model = msg.model
url = self._make_url(cr, uid, res_id, model)
- name = self.pool.get(model).name_get(cr, uid, res_id)[1]
- return (model, res_id, url, name)
+ name = self.pool.get(model).name_get(cr, uid, [res_id])[0][1]
+ return (model,res_id, url,name)
+
def document_type(self, cr, uid, context=None):
"""
@@ -90,12 +90,10 @@ class plugin_handler(osv.osv_memory):
"""
mail_message = self.pool.get('mail.message')
model_obj = self.pool.get(model)
-
msg = mail_message.parse_message(email)
message_id = msg.get('message-id')
-
-
mail_ids = mail_message.search(cr, uid, [('message_id','=',message_id),('res_id','=',res_id),('model','=',model)])
+
if message_id and mail_ids :
mail_record = mail_message.browse(cr, uid, mail_ids)[0]
res_id = mail_record.res_id
@@ -107,8 +105,12 @@ class plugin_handler(osv.osv_memory):
res_id = model_obj.message_new(cr, uid, msg)
notify = "Mail succefully pushed, a new %s has been created " % model
else:
- model_obj.message_append_dict(cr, uid, [res_id], msg)
+ if model == 'res.partner':
+ model_obj = self.pool.get('mail.thread')
+ res = self.pool.get(model).browse(cr, uid, [res_id])
+ model_obj.message_append_dict(cr, uid, res, msg)
notify = "Mail succefully pushed"
+
url = self._make_url(cr, uid, res_id, model)
return (model, res_id, url, notify)
@@ -130,8 +132,7 @@ class plugin_handler(osv.osv_memory):
return ('res.partner', partner_id, url)
# Specific to outlook rfc822 is not available so we split in arguments headerd,body,attachemnts
- def push_message_outlook(self, cr, uid, model, headers, body_text, body_html, attachments):
- pass
+ def push_message_outlook(self, cr, uid, model, headers,res_id=0 ,body_text=False, body_html=False, attachments=False):
# ----------------------------------------
# solution 1
# construct a fake rfc822 from the separated arguement
@@ -142,12 +143,23 @@ class plugin_handler(osv.osv_memory):
# solution 2
# use self.pushmessage only with header and body
# add attachemnt yourself after
-
- #ir_attachment_obj = self.pool.get('ir.attachment')
- #attachment_ids = ir_attachment_obj.search(cr, uid, [('res_model', '=', data.get('res_model')), ('res_id', '=', data.get('res_id')), ('datas_fname', '=', data.get('datas_fname'))])
- #if attachment_ids:
- # return attachment_ids[0]
- #else:
- # vals = {"res_model": data.get('res_model'), "res_id": data.get('res_id'), "name": data.get('name'), "datas" : data.get('datas'), "datas_fname" : data.get('datas_fname')}
- # return ir_attachment_obj.create(cr, uid, vals)
- #return (model, res_id, url, notify)
+ mail_message = self.pool.get('mail.message')
+ ir_attachment_obj = self.pool.get('ir.attachment')
+ attach_ids = []
+ msg = mail_message.parse_message(headers)
+ message_id = msg.get('message-id')
+ push_mail = self.push_message(cr, uid, model, headers, res_id)
+ res_id = push_mail[1]
+ model = push_mail[0]
+ for name in attachments.keys():
+ attachment_ids = ir_attachment_obj.search(cr, uid, [('res_model', '=', model), ('res_id', '=', res_id), ('datas_fname', '=', name)])
+ if attachment_ids:
+ attach_ids.append( attachment_ids[0])
+ else:
+ vals = {"res_model": model, "res_id": res_id, "name": name, "datas" :attachments[name], "datas_fname" : name}
+ attach_ids.append(ir_attachment_obj.create(cr, uid, vals))
+ mail_ids = mail_message.search(cr, uid, [('message_id','=',message_id),('res_id','=',res_id),('model','=',model)])
+ if mail_ids:
+ ids = mail_message.write(cr, uid,mail_ids[0],{ 'attachment_ids': [(6, 0, attach_ids)],'body_text':body_text,'body_html':body_html})
+ url = self._make_url(cr, uid, res_id, model)
+ return (model, res_id, url)