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 _
27 class crm_opportunity2phonecall(osv.osv_memory):
28 """Converts Opportunity to Phonecall"""
29 _inherit = 'crm.phonecall2phonecall'
30 _name = 'crm.opportunity2phonecall'
31 _description = 'Opportunity to Phonecall'
33 def default_get(self, cr, uid, fields, context=None):
34 opp_obj = self.pool.get('crm.lead')
36 data_obj = self.pool.get('ir.model.data')
37 res_id = data_obj._get_id(cr, uid, 'crm', 'categ_phone2')
39 categ_id = data_obj.browse(cr, uid, res_id, context=context).res_id
41 record_ids = context and context.get('active_ids', []) or []
43 res.update({'action': 'log', 'date': time.strftime('%Y-%m-%d %H:%M:%S')})
44 for opp in opp_obj.browse(cr, uid, record_ids, context=context):
46 res.update({'name': opp.name})
47 if 'user_id' in fields:
48 res.update({'user_id': opp.user_id and opp.user_id.id or False})
49 if 'section_id' in fields:
50 res.update({'section_id': opp.section_id and opp.section_id.id or False})
51 if 'categ_id' in fields:
52 res.update({'categ_id': categ_id})
53 if 'partner_id' in fields:
54 res.update({'partner_id': opp.partner_id and opp.partner_id.id or False})
56 res.update({'note': opp.description})
57 if 'contact_name' in fields:
58 res.update({'contact_name': opp.partner_id and opp.partner_id.name or False})
60 res.update({'phone': opp.phone or (opp.partner_id and opp.partner_id.phone or False)})
63 def action_schedule(self, cr, uid, ids, context=None):
67 phonecall = self.pool.get('crm.phonecall')
68 opportunity_ids = context and context.get('active_ids') or []
69 opportunity = self.pool.get('crm.lead')
70 data = self.browse(cr, uid, ids, context=context)[0]
71 call_ids = opportunity.schedule_phonecall(cr, uid, opportunity_ids, data.date, data.name, \
72 data.note, data.phone, data.contact_name, data.user_id and data.user_id.id or False, \
73 data.section_id and data.section_id.id or False, \
74 data.categ_id and data.categ_id.id or False, \
75 action=data.action, context=context)
76 return {'type': 'ir.actions.act_window_close'}
78 crm_opportunity2phonecall()
80 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: