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