diff options
| author | Cedric Snauwaert <csn@openerp.com> | 2012-11-19 16:45:51 +0100 |
|---|---|---|
| committer | Cedric Snauwaert <csn@openerp.com> | 2012-11-19 16:45:51 +0100 |
| commit | 7e193e691cba10cb0f297de47bfd53ef27665768 (patch) | |
| tree | 0dc14e23a09aaa6921cc4aa03aa0aee33249d2ed /addons/plugin/plugin_handler.py | |
| parent | 2ebf9e89fad0729b85bb8844e575ad2149bd9a1b (diff) | |
| parent | d9d127403b71d3fd401d3baf37b522b20ba89278 (diff) | |
[MERGE]merge with latest addons
bzr revid: csn@openerp.com-20121119154551-y8uizex6hu7fu1eo
Diffstat (limited to 'addons/plugin/plugin_handler.py')
| -rw-r--r-- | addons/plugin/plugin_handler.py | 83 |
1 files changed, 43 insertions, 40 deletions
diff --git a/addons/plugin/plugin_handler.py b/addons/plugin/plugin_handler.py index e497f902dc2..95fe80f3b29 100644 --- a/addons/plugin/plugin_handler.py +++ b/addons/plugin/plugin_handler.py @@ -6,7 +6,6 @@ Created on 18 oct. 2011 from osv import osv, fields - class plugin_handler(osv.osv_memory): _name = 'plugin.handler' @@ -37,28 +36,30 @@ 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, url, name_get) + (model_name, res_id, url, name_get) """ mail_message_obj = self.pool.get('mail.message') model = "" res_id = 0 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]) + msg = self.pool.get('mail.thread').message_parse(cr, uid, email) + parent_id = msg.get('parent_id', False) + message_id = msg.get('message_id') + msg_id = False + if message_id: + msg_ids = mail_message_obj.search(cr, uid, [('message_id','=', message_id)]) + msg_id = len(msg_ids) and msg_ids[0] or False + if not msg_id and parent_id: + msg_id = parent_id + if msg_id: + msg = mail_message_obj.browse(cr, uid, msg_id) 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])[0][1] return (model,res_id, url,name) - def document_type(self, cr, uid, context=None): """ Return the list of available model to push @@ -71,69 +72,71 @@ class plugin_handler(osv.osv_memory): doc_dict['res.partner'] = "Partner" return doc_dict.items() - # Can be used where search record was used + # Can be used where search record was used def list_document_get(self, cr, uid, model, name): """ This function return the result of name_search on the object model - @param model: the name of the model + @param model: the name of the model @param : the name of the document - @return : the result of name_search a list of tuple + @return : the result of name_search a list of tuple [(id, 'name')] """ - return self.pool.get(model).name_search(cr,uid,name) + return self.pool.get(model).name_search(cr, uid, name) def push_message(self, cr, uid, model, email, res_id=0): """ @param email: email is a standard RFC2822 email message @param model: On which model the message is pushed - @param thread_id: on which document the message is pushed, if thread_id = 0 a new document is created + @param thread_id: on which document the message is pushed, if thread_id = 0 a new document is created @return Dictionary which contain model , url and resource id. """ mail_message = self.pool.get('mail.message') model_obj = self.pool.get(model) - msg = mail_message.parse_message(email) + msg = self.pool.get('mail.thread').message_parse(cr, uid, 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 notify = "Email already pushed" elif res_id == 0: if model == 'res.partner': - notify = 'User the button Partner to create a new partner' + notify = 'User the Partner button to create a new partner' else: - res_id = model_obj.message_new(cr, uid, msg) - notify = "Mail succefully pushed, a new %s has been created " % model + res_id = model_obj.message_process(cr, uid, model, email) + notify = "Mail successfully pushed, a new %s has been created " % model else: - 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" - + model_obj.message_post(cr, uid, [res_id], + body= msg.get('body'), + subject= msg.get('subject'), + type= 'email', + parent_id= msg.get('parent_id'), + attachments= msg.get('attachments')) + notify = "Mail successfully pushed" url = self._make_url(cr, uid, res_id, model) return (model, res_id, url, notify) - def contact_create(self, cr, uid, data, partner_id): + def contact_create(self, cr, uid, data, partner_id, context=None): """ @param data : the data use to create the res.partner [('field_name', value)], field name is required - @param partner_id : On which partner the address is attached + @param partner_id : On which partner the address is attached if partner_id = 0 then create a new partner with the same name that the address @return : the partner_id sended or created, this allow the plugin to open the right partner page """ partner_obj = self.pool.get('res.partner') - dictcreate = dict(data) - if partner_id == 0: - partner_id = partner_obj.create(cr, uid, {'name':dictcreate.get('name')}) - dictcreate['partner_id'] = partner_id - self.pool.get('res.partner').create(cr, uid, dictcreate) + dictcreate = dict(data) + if partner_id: + is_company = partner_obj.browse(cr, uid, partner_id, context=context).is_company + if is_company: + dictcreate['parent_id'] = partner_id + partner_id = partner_obj.create(cr, uid, dictcreate) url = self._make_url(cr, uid, partner_id, 'res.partner') 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,res_id=0 ,body_text=False, body_html=False, attachments=False): + def push_message_outlook(self, cr, uid, model, headers, res_id=0, body=False, body_html=False, attachments=False): # ---------------------------------------- # solution 1 # construct a fake rfc822 from the separated arguement @@ -144,14 +147,14 @@ class plugin_handler(osv.osv_memory): # solution 2 # use self.pushmessage only with header and body # add attachemnt yourself after - mail_message = self.pool.get('mail.message') + 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') + msg = self.pool.get('mail.thread').message_parse(cr, uid, 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] + 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: @@ -161,6 +164,6 @@ class plugin_handler(osv.osv_memory): 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}) + ids = mail_message.write(cr, uid, mail_ids[0], { 'attachment_ids': [(6, 0, attach_ids)],'body':body,'body_html':body_html}) url = self._make_url(cr, uid, res_id, model) return (model, res_id, url) |
