[TYPO] Set the right category for the Point Of Sale
[odoo/odoo.git] / addons / crm / wizard / crm_phonecall_to_opportunity.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_phonecall2opportunity(osv.osv_memory):
26     """ Converts Phonecall to Opportunity"""
27
28     _name = 'crm.phonecall2opportunity'
29     _inherit = 'crm.partner2opportunity'
30     _description = 'Phonecall To Opportunity'
31
32     def make_opportunity(self, cr, uid, ids, context=None):
33         """
34         This converts Phonecall to Opportunity and opens Phonecall view
35         """
36         if not len(ids):
37             return False
38         call_ids = context and context.get('active_ids', False) or False
39         this = self.browse(cr, uid, ids[0], context=context)
40         if not call_ids:
41             return {}
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)
47
48     def default_get(self, cr, uid, fields, context=None):
49         """
50         This function gets default values
51         """
52         record_id = context and context.get('active_id', False) or False
53         res = {}
54
55         if record_id:
56             phonecall = self.pool.get('crm.phonecall').browse(cr, uid, record_id, context=context)
57             if 'name' in fields:
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})
61         return res
62
63 crm_phonecall2opportunity()
64
65 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: