[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:
Gery Debongnie 2014-05-07 12:09:54 +02:00
parent 88cef3a8eb
commit 9f3abe3ea4
2 changed files with 7 additions and 9 deletions

View File

@ -216,13 +216,11 @@ class crm_lead(format_address, osv.osv):
res[lead.id][field] = abs(int(duration)) res[lead.id][field] = abs(int(duration))
return res return res
def _meeting_count(self, cr, uid, ids, field_name, arg, context=None): def _meeting_count(self, cr, uid, ids, field_name, arg, context=None):
res = dict(map(lambda x: (x,0), ids)) Event = self.pool['calendar.event']
try: return {
for meeting in self.browse(cr, uid, ids, context=context): opp_id: Event.search_count(cr,uid, [('opportunity_id', '=', opp_id)], context=context)
res[meeting.id] = len(meeting.meeting_ids) for opp_id in ids
except: }
pass
return res
_columns = { _columns = {
'partner_id': fields.many2one('res.partner', 'Partner', ondelete='set null', track_visibility='onchange', '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."), 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', \ 'payment_mode': fields.many2one('crm.payment.mode', 'Payment Mode', \
domain="[('section_id','=',section_id)]"), domain="[('section_id','=',section_id)]"),
'planned_cost': fields.float('Planned Costs'), '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'), 'meeting_count': fields.function(_meeting_count, string='# Meetings', type='integer'),
} }

View File

@ -33,10 +33,11 @@ class res_partner(osv.osv):
res[partner.id] = { res[partner.id] = {
'opportunity_count': len(partner.opportunity_ids), 'opportunity_count': len(partner.opportunity_ids),
'meeting_count': len(partner.meeting_ids), 'meeting_count': len(partner.meeting_ids),
'phonecall_count': len(partner.meeting_ids),
} }
except: except:
pass pass
for partner in self.browse(cr, uid, ids, context):
res[partner.id]['phonecall_count'] = len(partner.phonecall_ids)
return res return res
_columns = { _columns = {