[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
This commit is contained in:
parent
88cef3a8eb
commit
9f3abe3ea4
|
@ -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'),
|
||||
}
|
||||
|
||||
|
|
|
@ -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 = {
|
||||
|
|
Loading…
Reference in New Issue