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 rec_ids = context and context.get('active_ids', [])
44 for phonecall in phonecall_obj.browse(cr, uid, rec_ids, context=context):
45 partner_ids = partner_obj.search(cr, uid, [('name', '=', phonecall.name or phonecall.name)])
46 if not partner_ids and (phonecall.partner_phone or phonecall.partner_mobile):
47 partner_ids = partner_obj.search(cr, uid, ['|', ('phone', '=', phonecall.partner_phone), ('mobile','=',phonecall.partner_mobile)])
49 partner_id = partner_ids and partner_ids[0] or False
53 def _create_partner(self, cr, uid, ids, context=None):
55 This function Creates partner based on action.
59 phonecall = self.pool.get('crm.phonecall')
61 data = self.browse(cr, uid, ids, context=context)[0]
62 call_ids = context and context.get('active_ids') or []
63 partner_id = data.partner_id and data.partner_id.id or False
64 partner_ids = phonecall.convert_partner(cr, uid, call_ids, data.action, partner_id, context=context)
65 return partner_ids[call_ids[0]]
67 crm_phonecall2partner()
69 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: