From a3f61bd9a7a7eb5c5772927b47101e4261a90464 Mon Sep 17 00:00:00 2001 From: "tfr@openerp.com" <> Date: Tue, 22 Nov 2011 11:44:48 +0100 Subject: [ADD] common api for plugin bzr revid: tfr@openerp.com-20111122104448-5uo0dd0g50yhk2cq --- addons/plugin/__init__.py | 25 +++++++ addons/plugin/__openerp__.py | 45 ++++++++++++ addons/plugin/plugin_handler.py | 151 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 221 insertions(+) create mode 100644 addons/plugin/__init__.py create mode 100644 addons/plugin/__openerp__.py create mode 100644 addons/plugin/plugin_handler.py (limited to 'addons/plugin') diff --git a/addons/plugin/__init__.py b/addons/plugin/__init__.py new file mode 100644 index 00000000000..1844c42011c --- /dev/null +++ b/addons/plugin/__init__.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2010 Tiny SPRL (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +import plugin_handler + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: + diff --git a/addons/plugin/__openerp__.py b/addons/plugin/__openerp__.py new file mode 100644 index 00000000000..b598690cbf2 --- /dev/null +++ b/addons/plugin/__openerp__.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2010 Tiny SPRL (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + + +{ + 'name': 'Common interface for CRM plugin (Thunderbird and Outlook)', + 'version': '1.0', + 'category': 'Hidden', + 'complexity': "easy", + 'description': """ +The common interface for pugin. +===================================================== + +""", + 'author': 'OpenERP SA', + 'website': 'http://www.openerp.com', + 'depends': [ + 'base', + ], + 'data': [], + 'demo': [], + 'test': [], + 'installable': True, + 'active': False, + 'images': [], +} +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/plugin/plugin_handler.py b/addons/plugin/plugin_handler.py new file mode 100644 index 00000000000..25ebe7fde80 --- /dev/null +++ b/addons/plugin/plugin_handler.py @@ -0,0 +1,151 @@ +''' +Created on 18 oct. 2011 + +@author: openerp +''' + +from osv import osv, fields + + +class plugin_handler(osv.osv_memory): + _name = 'plugin.handler' + + def _make_url(self, cr, uid, res_id, model, context=None): + """ + @param 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) + return base_url + + def is_installed(self, cr, uid): + return True + + def partner_get(self, cr, uid, address_email): + ids = self.pool.get('res.partner.address').search(cr, uid, [('partner_id', '!=', False), ('email', 'like', address_email)]) + res_id = ids and self.pool.get('res.partner.address').browse(cr, uid, ids[0]).partner_id.id or 0 + url = self._make_url(cr, uid, res_id, 'res.partner') + return ('res.partner', res_id , url) + + def document_get(self, cr, uid, email): + """ + @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) + """ + mail_message_obj = self.pool.get('mail.message') + model = False + res_id = 0 + url = False + + 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) + return (model, res_id, url) + + def document_type(self, cr, uid, context=None): + """ + Return the list of available model to push + res.partner is a special case + otherwise all model that inherit from mail.thread + ['res.partner', 'project.issue'] + """ + mail_thread_obj = self.pool.get('mail.thread') + doc_dict = mail_thread_obj.message_capable_models(cr, uid, context) + doc_dict['res.partner'] = "Partner" + return doc_dict.items() + + 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 : the name of the document + @return : the result of name_search a list of tuple + [(id, '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 + @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) + 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' + else: + 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) + notify = "Mail succefully 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): + """ + @param data : the data use to create the res.partner.address + [('field_name', value)], field name is required + @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 + """ + print "create contact", data, partner_id + 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.address').create(cr, uid, dictcreate) + url = self._make_url(cr, uid, partner_id, 'res.partner') + return ('res.partner', partner_id, url) + + + + ############################## + # # + # Specific to outlook # + # # + ############################## + + def attachment_create(self,cr, uid, data): + """ + @param data : the data use to create the ir.attachment + [('field_name', value)], field name is required. + """ + 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) + -- cgit v1.2.3 From 784bf2fcbead0e8480e98099897b74e0b34b2c2d Mon Sep 17 00:00:00 2001 From: "tfr@openerp.com" <> Date: Tue, 22 Nov 2011 11:52:02 +0100 Subject: [CLEAN] remove print bzr revid: tfr@openerp.com-20111122105202-13mhvor9gvo1nwpo --- addons/plugin/plugin_handler.py | 1 - 1 file changed, 1 deletion(-) (limited to 'addons/plugin') diff --git a/addons/plugin/plugin_handler.py b/addons/plugin/plugin_handler.py index 25ebe7fde80..202b050c722 100644 --- a/addons/plugin/plugin_handler.py +++ b/addons/plugin/plugin_handler.py @@ -118,7 +118,6 @@ class plugin_handler(osv.osv_memory): 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 """ - print "create contact", data, partner_id partner_obj = self.pool.get('res.partner') dictcreate = dict(data) if partner_id == 0: -- cgit v1.2.3 From 2503908223188a55d9fefef2edb72dc65fd62590 Mon Sep 17 00:00:00 2001 From: Antony Lesuisse Date: Tue, 22 Nov 2011 16:55:25 +0530 Subject: [IMP] outlook function prototype for plugin bzr revid: al@openerp.com-20111122112525-wf86e3q6tgb2mgas --- addons/plugin/plugin_handler.py | 59 +++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 29 deletions(-) (limited to 'addons/plugin') diff --git a/addons/plugin/plugin_handler.py b/addons/plugin/plugin_handler.py index 202b050c722..b21f7423263 100644 --- a/addons/plugin/plugin_handler.py +++ b/addons/plugin/plugin_handler.py @@ -9,7 +9,7 @@ from osv import osv, fields class plugin_handler(osv.osv_memory): _name = 'plugin.handler' - + def _make_url(self, cr, uid, res_id, model, context=None): """ @param id: on which document the message is pushed @@ -20,16 +20,16 @@ class plugin_handler(osv.osv_memory): if base_url: base_url += '/?id=%s&model=%s'%(res_id,model) return base_url - + def is_installed(self, cr, uid): return True - + def partner_get(self, cr, uid, address_email): ids = self.pool.get('res.partner.address').search(cr, uid, [('partner_id', '!=', False), ('email', 'like', address_email)]) res_id = ids and self.pool.get('res.partner.address').browse(cr, uid, ids[0]).partner_id.id or 0 url = self._make_url(cr, uid, res_id, 'res.partner') return ('res.partner', res_id , url) - + def document_get(self, cr, uid, email): """ @param email: email is a standard RFC2822 email message @@ -55,7 +55,7 @@ class plugin_handler(osv.osv_memory): model = msg.model url = self._make_url(cr, uid, res_id, model) return (model, res_id, url) - + def document_type(self, cr, uid, context=None): """ Return the list of available model to push @@ -68,6 +68,7 @@ class plugin_handler(osv.osv_memory): doc_dict['res.partner'] = "Partner" return doc_dict.items() + # 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 @@ -77,7 +78,7 @@ class plugin_handler(osv.osv_memory): [(id, '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 @@ -108,8 +109,7 @@ class plugin_handler(osv.osv_memory): notify = "Mail succefully 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): """ @param data : the data use to create the res.partner.address @@ -126,25 +126,26 @@ class plugin_handler(osv.osv_memory): self.pool.get('res.partner.address').create(cr, uid, dictcreate) url = self._make_url(cr, uid, partner_id, 'res.partner') return ('res.partner', partner_id, url) - - - - ############################## - # # - # Specific to outlook # - # # - ############################## - - def attachment_create(self,cr, uid, data): - """ - @param data : the data use to create the ir.attachment - [('field_name', value)], field name is required. - """ - 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) + # 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 + # ---------------------------------------- + # solution 1 + # construct a fake rfc822 from the separated arguement + #m = email.asdfsadf + # use the push_message method + #self.push_message(m) + # ---------------------------------------- + # 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) -- cgit v1.2.3 From 1ca5b10918ff2c2bc81a4cad616bd6fcea81eef9 Mon Sep 17 00:00:00 2001 From: Antony Lesuisse Date: Wed, 23 Nov 2011 12:46:51 +0530 Subject: [FIX] project data, plugin document_get bzr revid: al@openerp.com-20111123071651-0frq669h3f9cm7tu --- addons/plugin/plugin_handler.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'addons/plugin') diff --git a/addons/plugin/plugin_handler.py b/addons/plugin/plugin_handler.py index b21f7423263..c4859771e35 100644 --- a/addons/plugin/plugin_handler.py +++ b/addons/plugin/plugin_handler.py @@ -41,20 +41,22 @@ class plugin_handler(osv.osv_memory): model = False res_id = 0 url = False + 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) - return (model, res_id, url) + name = self.pool.get(model).name_get(cr, uid, res_id)[1] + return (model, res_id, url, name) def document_type(self, cr, uid, context=None): """ -- cgit v1.2.3 From 4e0befa1f4d944c3265d780f421a72fd64a878b2 Mon Sep 17 00:00:00 2001 From: Fabien Pinckaers Date: Tue, 6 Dec 2011 13:03:55 +0100 Subject: [IMP] better manifests on modules bzr revid: fp@tinyerp.com-20111206120355-h5vufbibzovtvf0j --- addons/plugin/__openerp__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'addons/plugin') diff --git a/addons/plugin/__openerp__.py b/addons/plugin/__openerp__.py index b598690cbf2..2b05305c5ce 100644 --- a/addons/plugin/__openerp__.py +++ b/addons/plugin/__openerp__.py @@ -21,9 +21,9 @@ { - 'name': 'Common interface for CRM plugin (Thunderbird and Outlook)', + 'name': 'CRM Plugins', 'version': '1.0', - 'category': 'Hidden', + 'category': 'Tools', 'complexity': "easy", 'description': """ The common interface for pugin. -- cgit v1.2.3