[FIX] crm: Put action_cancel method for closing wizard of schedule call to opportunity
[odoo/odoo.git] / addons / crm / wizard / crm_phonecall_to_partner.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
6 #
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.
11 #
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.
16 #
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/>.
19 #
20 ##############################################################################
21
22 from osv import osv, fields
23 from tools.translate import _
24
25 class crm_phonecall2partner(osv.osv_memory):
26     """ Converts phonecall to partner """
27
28     _name = 'crm.phonecall2partner'
29     _inherit = 'crm.lead2partner'
30     _description = 'Phonecall to Partner'
31     
32     def _select_partner(self, cr, uid, context=None):
33         """
34         This function Searches for Partner from selected phonecall.
35         """
36         if context is None:
37             context = {}
38
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', [])
43         value = {}
44
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)])
49                 if address_ids:
50                     addresses = contact_obj.browse(cr, uid, address_ids)
51                     partner_ids = addresses and [addresses[0].partner_id.id] or False
52
53             partner_id = partner_ids and partner_ids[0] or False
54         return partner_id
55
56
57     def _create_partner(self, cr, uid, ids, context=None):
58         """
59         This function Creates partner based on action.
60         """
61         if context is None:
62             context = {}
63         phonecall = self.pool.get('crm.phonecall')
64
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]]
70
71 crm_phonecall2partner()
72
73 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: