2010-05-25 12:23:58 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
##############################################################################
|
|
|
|
#
|
|
|
|
# OpenERP, Open Source Management Solution
|
|
|
|
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
# License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
2012-12-06 14:56:32 +00:00
|
|
|
from openerp.osv import fields,osv
|
2010-05-25 12:23:58 +00:00
|
|
|
|
|
|
|
class res_partner(osv.osv):
|
|
|
|
""" Inherits partner and adds CRM information in the partner form """
|
|
|
|
_inherit = 'res.partner'
|
2012-04-26 10:31:33 +00:00
|
|
|
|
2014-03-14 14:01:14 +00:00
|
|
|
def _opportunity_meeting_phonecall_count(self, cr, uid, ids, field_name, arg, context=None):
|
2012-09-28 08:18:05 +00:00
|
|
|
res = dict(map(lambda x: (x,{'opportunity_count': 0, 'meeting_count': 0}), ids))
|
|
|
|
# the user may not have access rights for opportunities or meetings
|
|
|
|
try:
|
|
|
|
for partner in self.browse(cr, uid, ids, context):
|
2015-01-27 18:13:53 +00:00
|
|
|
if partner.is_company:
|
|
|
|
operator = 'child_of'
|
|
|
|
else:
|
|
|
|
operator = '='
|
|
|
|
opp_ids = self.pool['crm.lead'].search(cr, uid, [('partner_id', operator, partner.id), ('type', '=', 'opportunity'), ('probability', '<', '100')], context=context)
|
2012-09-28 08:18:05 +00:00
|
|
|
res[partner.id] = {
|
2015-01-06 10:31:08 +00:00
|
|
|
'opportunity_count': len(opp_ids),
|
2012-09-28 08:18:05 +00:00
|
|
|
'meeting_count': len(partner.meeting_ids),
|
|
|
|
}
|
|
|
|
except:
|
|
|
|
pass
|
2015-07-22 13:52:39 +00:00
|
|
|
return res
|
|
|
|
|
|
|
|
def _phonecall_count(self, cr, uid, ids, field_name, arg, context=None):
|
|
|
|
res = {}
|
2014-05-07 10:09:54 +00:00
|
|
|
for partner in self.browse(cr, uid, ids, context):
|
2015-07-22 13:52:39 +00:00
|
|
|
res[partner.id] = len(partner.phonecall_ids)
|
2012-05-04 14:55:51 +00:00
|
|
|
return res
|
2012-05-01 13:20:24 +00:00
|
|
|
|
2010-05-25 12:23:58 +00:00
|
|
|
_columns = {
|
2011-08-25 04:10:37 +00:00
|
|
|
'section_id': fields.many2one('crm.case.section', 'Sales Team'),
|
2010-06-25 21:21:53 +00:00
|
|
|
'opportunity_ids': fields.one2many('crm.lead', 'partner_id',\
|
2013-09-05 14:48:37 +00:00
|
|
|
'Leads and Opportunities', domain=[('probability', 'not in', ['0', '100'])]),
|
2014-03-12 13:23:47 +00:00
|
|
|
'meeting_ids': fields.many2many('calendar.event', 'calendar_event_res_partner_rel','res_partner_id', 'calendar_event_id',
|
2012-05-22 14:54:33 +00:00
|
|
|
'Meetings'),
|
2010-06-25 21:21:53 +00:00
|
|
|
'phonecall_ids': fields.one2many('crm.phonecall', 'partner_id',\
|
2010-07-14 15:17:13 +00:00
|
|
|
'Phonecalls'),
|
2014-03-14 14:01:14 +00:00
|
|
|
'opportunity_count': fields.function(_opportunity_meeting_phonecall_count, string="Opportunity", type='integer', multi='opp_meet'),
|
|
|
|
'meeting_count': fields.function(_opportunity_meeting_phonecall_count, string="# Meetings", type='integer', multi='opp_meet'),
|
2015-07-22 13:52:39 +00:00
|
|
|
'phonecall_count': fields.function(_phonecall_count, string="Phonecalls", type="integer"),
|
2010-06-25 21:21:53 +00:00
|
|
|
}
|
2011-10-21 07:01:11 +00:00
|
|
|
|
2011-10-24 13:30:10 +00:00
|
|
|
def redirect_partner_form(self, cr, uid, partner_id, context=None):
|
2011-11-03 06:14:32 +00:00
|
|
|
search_view = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'base', 'view_res_partner_filter')
|
2011-10-24 13:30:10 +00:00
|
|
|
value = {
|
|
|
|
'domain': "[]",
|
|
|
|
'view_type': 'form',
|
|
|
|
'view_mode': 'form,tree',
|
|
|
|
'res_model': 'res.partner',
|
|
|
|
'res_id': int(partner_id),
|
|
|
|
'view_id': False,
|
|
|
|
'context': context,
|
|
|
|
'type': 'ir.actions.act_window',
|
2011-11-03 06:14:32 +00:00
|
|
|
'search_view_id': search_view and search_view[1] or False
|
2011-10-24 13:30:10 +00:00
|
|
|
}
|
|
|
|
return value
|
|
|
|
|
|
|
|
def make_opportunity(self, cr, uid, ids, opportunity_summary, planned_revenue=0.0, probability=0.0, partner_id=None, context=None):
|
2012-03-30 09:08:37 +00:00
|
|
|
categ_obj = self.pool.get('crm.case.categ')
|
|
|
|
categ_ids = categ_obj.search(cr, uid, [('object_id.model','=','crm.lead')])
|
|
|
|
lead_obj = self.pool.get('crm.lead')
|
2011-10-24 13:30:10 +00:00
|
|
|
opportunity_ids = {}
|
2011-10-21 07:01:11 +00:00
|
|
|
for partner in self.browse(cr, uid, ids, context=context):
|
|
|
|
if not partner_id:
|
|
|
|
partner_id = partner.id
|
2012-03-30 09:08:37 +00:00
|
|
|
opportunity_id = lead_obj.create(cr, uid, {
|
2011-10-24 13:30:10 +00:00
|
|
|
'name' : opportunity_summary,
|
2011-10-21 07:01:11 +00:00
|
|
|
'planned_revenue' : planned_revenue,
|
|
|
|
'probability' : probability,
|
|
|
|
'partner_id' : partner_id,
|
2012-08-13 13:12:07 +00:00
|
|
|
'categ_ids' : categ_ids and categ_ids[0:1] or [],
|
2011-10-21 07:01:11 +00:00
|
|
|
'type': 'opportunity'
|
2011-12-22 09:10:55 +00:00
|
|
|
}, context=context)
|
2011-10-24 13:30:10 +00:00
|
|
|
opportunity_ids[partner_id] = opportunity_id
|
2011-10-21 07:01:11 +00:00
|
|
|
return opportunity_ids
|
2010-05-25 12:23:58 +00:00
|
|
|
|
2014-04-17 14:56:45 +00:00
|
|
|
def schedule_meeting(self, cr, uid, ids, context=None):
|
|
|
|
partner_ids = list(ids)
|
|
|
|
partner_ids.append(self.pool.get('res.users').browse(cr, uid, uid).partner_id.id)
|
|
|
|
res = self.pool.get('ir.actions.act_window').for_xml_id(cr, uid, 'calendar', 'action_calendar_event', context)
|
|
|
|
res['context'] = {
|
2014-08-27 10:31:48 +00:00
|
|
|
'search_default_partner_ids': list(ids),
|
2014-04-17 14:56:45 +00:00
|
|
|
'default_partner_ids': partner_ids,
|
|
|
|
}
|
|
|
|
return res
|