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 fields,osv
23 from tools.translate import _
25 class res_partner(osv.osv):
26 """ Inherits partner and adds CRM information in the partner form """
27 _inherit = 'res.partner'
29 def _opportunity_count(self, cr, uid, ids, field_name, arg, context=None):
30 count = dict.fromkeys(ids, 0)
31 opportunity_pool=self.pool.get('crm.lead')
32 opportunity_ids = opportunity_pool.search(cr, uid, [('partner_id', 'in', ids)])
33 for opportunity in opportunity_pool.browse(cr, uid, opportunity_ids):
34 count[opportunity.partner_id.id] += 1
37 def _meeting_count(self, cr, uid, ids, field_name, arg, context=None):
38 count = dict.fromkeys(ids, 0)
39 meeting_pool=self.pool.get('crm.meeting')
40 meeting_ids = meeting_pool.search(cr, uid, [('partner_id', 'in', ids)])
41 for meeting in meeting_pool.browse(cr, uid, meeting_ids):
42 count[meeting.partner_id.id] += 1
46 'section_id': fields.many2one('crm.case.section', 'Sales Team'),
47 'opportunity_ids': fields.one2many('crm.lead', 'partner_id',\
48 'Leads and Opportunities'),
49 'meeting_ids': fields.one2many('crm.meeting', 'partner_id',\
51 'phonecall_ids': fields.one2many('crm.phonecall', 'partner_id',\
53 'opportunity_count': fields.function(_opportunity_count , type='integer',string="Opportunity"),
54 'meeting_count': fields.function(_meeting_count , type='integer',string="Meeting"),
58 'opportunity_count': 0,
62 def redirect_partner_form(self, cr, uid, partner_id, context=None):
63 search_view = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'base', 'view_res_partner_filter')
67 'view_mode': 'form,tree',
68 'res_model': 'res.partner',
69 'res_id': int(partner_id),
72 'type': 'ir.actions.act_window',
73 'search_view_id': search_view and search_view[1] or False
77 def make_opportunity(self, cr, uid, ids, opportunity_summary, planned_revenue=0.0, probability=0.0, partner_id=None, context=None):
78 categ_obj = self.pool.get('crm.case.categ')
79 categ_ids = categ_obj.search(cr, uid, [('object_id.model','=','crm.lead')])
80 lead_obj = self.pool.get('crm.lead')
82 for partner in self.browse(cr, uid, ids, context=context):
84 partner_id = partner.id
85 opportunity_id = lead_obj.create(cr, uid, {
86 'name' : opportunity_summary,
87 'planned_revenue' : planned_revenue,
88 'probability' : probability,
89 'partner_id' : partner_id,
90 'categ_id' : categ_ids and categ_ids[0] or '',
94 opportunity_ids[partner_id] = opportunity_id
95 return opportunity_ids
99 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: