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_partner2opportunity(osv.osv_memory):
26 """Converts Partner To Opportunity"""
28 _name = 'crm.partner2opportunity'
29 _description = 'Partner To Opportunity'
32 'name' : fields.char('Opportunity Name', size=64, required=True),
33 'planned_revenue': fields.float('Expected Revenue', digits=(16,2)),
34 'probability': fields.float('Success Probability', digits=(16,2)),
35 'partner_id': fields.many2one('res.partner', 'Partner'),
38 def action_cancel(self, cr, uid, ids, context=None):
40 Closes Partner 2 Opportunity
42 return {'type':'ir.actions.act_window_close'}
44 def default_get(self, cr, uid, fields, context=None):
46 This function gets default values
48 partner_obj = self.pool.get('res.partner')
49 data = context and context.get('active_ids', []) or []
50 res = super(crm_partner2opportunity, self).default_get(cr, uid, fields, context=context)
52 for partner in partner_obj.browse(cr, uid, data, []):
54 res.update({'name': partner.name})
55 if 'partner_id' in fields:
56 res.update({'partner_id': data and data[0] or False})
59 def make_opportunity(self, cr, uid, ids, context=None):
60 partner_ids = context and context.get('active_ids', []) or []
61 partner_id = partner_ids[0] if partner_ids else None
62 partner = self.pool.get('res.partner')
63 lead = self.pool.get('crm.lead')
64 data = self.browse(cr, uid, ids, context=context)[0]
65 opportunity_ids = partner.make_opportunity(cr, uid, partner_ids,
72 opportunity_id = opportunity_ids[partner_ids[0]]
73 return lead.redirect_opportunity_view(cr, uid, opportunity_id, context=context)
75 crm_partner2opportunity()
77 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: