[IMP]:added icons on buttons.
[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
28     def _opportunity_meeting_count(self, cr, uid, ids, field_name, arg, context=None):
29         res = {}
30         for partner in self.browse(cr, uid, ids, context):
31             res[partner.id] = {
32                 'opportunity_count': len(partner.opportunity_ids),
33                 'meeting_count': len(partner.meeting_ids),
34             }
35         return res
36
37     _columns = {
38         'section_id': fields.many2one('crm.case.section', 'Sales Team'),
39         'opportunity_ids': fields.one2many('crm.lead', 'partner_id',\
40             'Leads and Opportunities', domain=[('state','in', ('draft','open','pending'))]),
41         'meeting_ids': fields.one2many('crm.meeting', 'partner_id',\
42             'Meetings'),
43         'phonecall_ids': fields.one2many('crm.phonecall', 'partner_id',\
44             'Phonecalls'),
45         'opportunity_count': fields.function(_opportunity_meeting_count, string="Opportunity", type='integer', multi='opp_meet'),
46         'meeting_count': fields.function(_opportunity_meeting_count, string="Meeting", type='integer', multi='opp_meet'),
47     }
48
49     def redirect_partner_form(self, cr, uid, partner_id, context=None):
50         search_view = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'base', 'view_res_partner_filter')
51         value = {
52             'domain': "[]",
53             'view_type': 'form',
54             'view_mode': 'form,tree',
55             'res_model': 'res.partner',
56             'res_id': int(partner_id),
57             'view_id': False,
58             'context': context,
59             'type': 'ir.actions.act_window',
60             'search_view_id': search_view and search_view[1] or False
61         }
62         return value
63
64     def make_opportunity(self, cr, uid, ids, opportunity_summary, planned_revenue=0.0, probability=0.0, partner_id=None, context=None):
65         categ_obj = self.pool.get('crm.case.categ')
66         categ_ids = categ_obj.search(cr, uid, [('object_id.model','=','crm.lead')])
67         lead_obj = self.pool.get('crm.lead')
68         opportunity_ids = {}
69         for partner in self.browse(cr, uid, ids, context=context):
70             if not partner_id:
71                 partner_id = partner.id
72             opportunity_id = lead_obj.create(cr, uid, {
73                 'name' : opportunity_summary,
74                 'planned_revenue' : planned_revenue,
75                 'probability' : probability,
76                 'partner_id' : partner_id,
77                 'categ_id' : categ_ids and categ_ids[0] or '',
78                 'state' :'draft',
79                 'type': 'opportunity'
80             }, context=context)
81             opportunity_ids[partner_id] = opportunity_id
82         return opportunity_ids
83 res_partner()
84
85
86 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: