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 _total_oppo(self, cr, uid, ids, field_name, arg, context=None):
31 oppo_pool=self.pool.get('crm.lead')
33 oppo_ids = oppo_pool.search(cr, uid, [('partner_id', '=', id)])
34 total_oppo[id] = len(oppo_ids)
37 def _total_meeting(self, cr, uid, ids, field_name, arg, context=None):
39 meeting_pool=self.pool.get('crm.meeting')
41 meeting_ids = meeting_pool.search(cr, uid, [('partner_id', '=', id)])
42 total_meeting[id] = len(meeting_ids)
47 'section_id': fields.many2one('crm.case.section', 'Sales Team'),
48 'opportunity_ids': fields.one2many('crm.lead', 'partner_id',\
49 'Leads and Opportunities'),
50 'meeting_ids': fields.one2many('crm.meeting', 'partner_id',\
52 'phonecall_ids': fields.one2many('crm.phonecall', 'partner_id',\
54 'total_oppo': fields.function(_total_oppo , type='integer',string="Total Opportunity"),
55 'total_meeting': fields.function(_total_meeting , type='integer',string="Total Meeting"),
63 def redirect_partner_form(self, cr, uid, partner_id, context=None):
64 search_view = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'base', 'view_res_partner_filter')
68 'view_mode': 'form,tree',
69 'res_model': 'res.partner',
70 'res_id': int(partner_id),
73 'type': 'ir.actions.act_window',
74 'search_view_id': search_view and search_view[1] or False
78 def get_opportunity(self, cr, uid, ids, context=None):
81 models_data = self.pool.get('ir.model.data')
83 form_view = models_data.get_object_reference(cr, uid, 'crm', 'crm_case_form_view_oppor')
84 tree_view = models_data.get_object_reference(cr, uid, 'crm', 'crm_case_tree_view_oppor')
85 search_view = models_data.get_object_reference(cr, uid, 'crm', 'view_crm_case_opportunities_filter')
86 partner_id = self.browse(cr, uid, ids[0], context=context)
87 domain =[('partner_id', '=', partner_id.id)]
90 'name': _('Opportunity'),
92 'view_mode': 'tree, form',
93 'res_model': 'crm.lead',
96 'views': [(tree_view and tree_view[1] or False, 'tree'),
97 (form_view and form_view[1] or False, 'form'),
98 (False, 'calendar'), (False, 'graph')],
99 'type': 'ir.actions.act_window',
100 'search_view_id': search_view and search_view[1] or False,
104 def make_opportunity(self, cr, uid, ids, opportunity_summary, planned_revenue=0.0, probability=0.0, partner_id=None, context=None):
105 categ_obj = self.pool.get('crm.case.categ')
106 categ_ids = categ_obj.search(cr, uid, [('object_id.model','=','crm.lead')])
107 lead_obj = self.pool.get('crm.lead')
109 for partner in self.browse(cr, uid, ids, context=context):
111 partner_id = partner.id
112 opportunity_id = lead_obj.create(cr, uid, {
113 'name' : opportunity_summary,
114 'planned_revenue' : planned_revenue,
115 'probability' : probability,
116 'partner_id' : partner_id,
117 'categ_id' : categ_ids and categ_ids[0] or '',
119 'type': 'opportunity'
121 opportunity_ids[partner_id] = opportunity_id
122 return opportunity_ids
126 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: