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_phonecall2opportunity(osv.osv_memory):
26 """ Converts Phonecall to Opportunity"""
28 _name = 'crm.phonecall2opportunity'
29 _inherit = 'crm.partner2opportunity'
30 _description = 'Phonecall To Opportunity'
32 def make_opportunity(self, cr, uid, ids, context=None):
34 This converts Phonecall to Opportunity and opens Phonecall view
38 call_ids = context and context.get('active_ids', False) or False
39 this = self.browse(cr, uid, ids[0], context=context)
42 opportunity = self.pool.get('crm.lead')
43 phonecall = self.pool.get('crm.phonecall')
44 opportunity_ids = phonecall.convert_opportunity(cr, uid, call_ids, this.name, this.partner_id and this.partner_id.id or False, \
45 this.planned_revenue, this.probability, context=context)
46 return opportunity.redirect_opportunity_view(cr, uid, opportunity_ids[call_ids[0]], context=context)
48 def default_get(self, cr, uid, fields, context=None):
50 This function gets default values
52 record_id = context and context.get('active_id', False) or False
53 res = super(crm_phonecall2opportunity, self).default_get(cr, uid, fields, context=context)
56 phonecall = self.pool.get('crm.phonecall').browse(cr, uid, record_id, context=context)
58 res.update({'name': phonecall.name})
59 if 'partner_id' in fields:
60 res.update({'partner_id': phonecall.partner_id and phonecall.partner_id.id or False})
63 crm_phonecall2opportunity()