1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##############################################################################
22 from osv import osv, fields
23 from tools.translate import _
25 class crm_phonecall2partner(osv.osv_memory):
26 """ Converts phonecall to partner """
28 _name = 'crm.phonecall2partner'
29 _inherit = 'crm.lead2partner'
30 _description = 'Phonecall to Partner'
32 def _select_partner(self, cr, uid, context=None):
34 This function Searches for Partner from selected phonecall.
39 phonecall_obj = self.pool.get('crm.phonecall')
40 partner_obj = self.pool.get('res.partner')
41 contact_obj = self.pool.get('res.partner.address')
42 rec_ids = context and context.get('active_ids', [])
45 for phonecall in phonecall_obj.browse(cr, uid, rec_ids, context=context):
46 partner_ids = partner_obj.search(cr, uid, [('name', '=', phonecall.name or phonecall.name)])
47 if not partner_ids and phonecall.email_from:
48 address_ids = contact_obj.search(cr, uid, ['|', ('phone', '=', phonecall.partner_phone), ('mobile','=',phonecall.partner_mobile)])
50 addresses = contact_obj.browse(cr, uid, address_ids)
51 partner_ids = addresses and [addresses[0].partner_id.id] or False
53 partner_id = partner_ids and partner_ids[0] or False
57 def _create_partner(self, cr, uid, ids, context=None):
59 This function Creates partner based on action.
63 phonecall = self.pool.get('crm.phonecall')
65 data = self.browse(cr, uid, ids, context=context)[0]
66 call_ids = context and context.get('active_ids') or []
67 partner_id = data.partner_id and data.partner_id.id or False
68 partner_ids = phonecall.convert_partner(cr, uid, call_ids, data.action, partner_id, context=context)
69 return partner_ids[call_ids[0]]
71 crm_phonecall2partner()
73 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: