[IMP] crm: clean test cases, APIs of crm.lead, crm.phonecall
[odoo/odoo.git] / addons / crm / res_partner.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 fields,osv
23
24 class res_partner(osv.osv):
25     """ Inherits partner and adds CRM information in the partner form """
26     _inherit = 'res.partner'
27     _columns = {
28         'section_id': fields.many2one('crm.case.section', 'Sales Team'),
29         'opportunity_ids': fields.one2many('crm.lead', 'partner_id',\
30             'Leads and Opportunities'),
31         'meeting_ids': fields.one2many('crm.meeting', 'partner_id',\
32             'Meetings'),
33         'phonecall_ids': fields.one2many('crm.phonecall', 'partner_id',\
34             'Phonecalls'),
35     }
36
37     def redirect_partner_form(self, cr, uid, partner_id, context=None):
38         model_data = self.pool.get('ir.model.data')
39         result = model_data._get_id(cr, uid, 'base', 'view_res_partner_filter')
40         res = model_data.read(cr, uid, result, ['res_id'])
41
42         value = {
43             'domain': "[]",
44             'view_type': 'form',
45             'view_mode': 'form,tree',
46             'res_model': 'res.partner',
47             'res_id': int(partner_id),
48             'view_id': False,
49             'context': context,
50             'type': 'ir.actions.act_window',
51             'search_view_id': res['res_id']
52         }
53         return value
54
55     def make_opportunity(self, cr, uid, ids, opportunity_summary, planned_revenue=0.0, probability=0.0, partner_id=None, context=None):
56         categ = self.pool.get('crm.case.categ')
57         address = self.address_get(cr, uid, ids)
58         categ_ids = categ.search(cr, uid, [('object_id.model','=','crm.lead')])
59         lead = self.pool.get('crm.lead')
60         opportunity_ids = {}
61         for partner in self.browse(cr, uid, ids, context=context):
62             address = self.address_get(cr, uid, [partner.id])['default']
63             if not partner_id:
64                 partner_id = partner.id
65             opportunity_id = lead.create(cr, uid, {
66                 'name' : opportunity_summary,
67                 'planned_revenue' : planned_revenue,
68                 'probability' : probability,
69                 'partner_id' : partner_id,
70                 'partner_address_id' : address,
71                 'categ_id' : categ_ids and categ_ids[0] or '',
72                 'state' :'draft',
73                 'type': 'opportunity'
74             })
75             opportunity_ids[partner_id] = opportunity_id
76         return opportunity_ids
77 res_partner()
78
79
80 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: