From 9f3abe3ea4d040b0ded7c4384077d799ecb24ab2 Mon Sep 17 00:00:00 2001 From: Gery Debongnie Date: Wed, 7 May 2014 12:09:54 +0200 Subject: [PATCH] [FIX] code cleanup (addon crm) improves the method to count opportunities/meetings/phonecalls in res_partner.py. It was bugged in two different way: the phonecall_count field was counting the number of meetings and not of phone calls, and it was in the try statement, so it might give an incorrect value if an exception occurs in the computation of opportunity/meeting Also, remove useless meeting_ids one2many field in crm_lead.py and improves the method meeting_count bzr revid: ged@openerp.com-20140507100954-1aqnd93iu5wsixob --- addons/crm/crm_lead.py | 13 +++++-------- addons/crm/res_partner.py | 3 ++- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/addons/crm/crm_lead.py b/addons/crm/crm_lead.py index db7ca79ff11..a9311c3be6a 100644 --- a/addons/crm/crm_lead.py +++ b/addons/crm/crm_lead.py @@ -216,13 +216,11 @@ class crm_lead(format_address, osv.osv): res[lead.id][field] = abs(int(duration)) return res def _meeting_count(self, cr, uid, ids, field_name, arg, context=None): - res = dict(map(lambda x: (x,0), ids)) - try: - for meeting in self.browse(cr, uid, ids, context=context): - res[meeting.id] = len(meeting.meeting_ids) - except: - pass - return res + Event = self.pool['calendar.event'] + return { + opp_id: Event.search_count(cr,uid, [('opportunity_id', '=', opp_id)], context=context) + for opp_id in ids + } _columns = { 'partner_id': fields.many2one('res.partner', 'Partner', ondelete='set null', track_visibility='onchange', select=True, help="Linked partner (optional). Usually created when converting the lead."), @@ -297,7 +295,6 @@ class crm_lead(format_address, osv.osv): 'payment_mode': fields.many2one('crm.payment.mode', 'Payment Mode', \ domain="[('section_id','=',section_id)]"), 'planned_cost': fields.float('Planned Costs'), - 'meeting_ids': fields.one2many('calendar.event', 'opportunity_id', 'Opportunities'), 'meeting_count': fields.function(_meeting_count, string='# Meetings', type='integer'), } diff --git a/addons/crm/res_partner.py b/addons/crm/res_partner.py index b34e5c7dbb9..bb216e2040e 100644 --- a/addons/crm/res_partner.py +++ b/addons/crm/res_partner.py @@ -33,10 +33,11 @@ class res_partner(osv.osv): res[partner.id] = { 'opportunity_count': len(partner.opportunity_ids), 'meeting_count': len(partner.meeting_ids), - 'phonecall_count': len(partner.meeting_ids), } except: pass + for partner in self.browse(cr, uid, ids, context): + res[partner.id]['phonecall_count'] = len(partner.phonecall_ids) return res _columns = {