# -*- coding: utf-8 -*- ############################################################################## # # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (). # # 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 . # ############################################################################## from openerp.osv import fields,osv class res_partner(osv.osv): """ Inherits partner and adds CRM information in the partner form """ _inherit = 'res.partner' #for partner in self.browse(cr, uid, ids, context): def _iniciativa_count(self, cr, uid, ids, field_name, arg, context=None): res = dict(map(lambda x: (x,0), ids)) # The current user may not have access rights for sale orders try: for partner in self.browse(cr, uid, ids, context): operator = '=' iniciativa_ids = self.pool['crm.lead'].search(cr, uid, [('partner_id', operator, partner.id), ('type', '=', 'lead')], context=context) res[partner.id] = len(partner.iniciativa_ids) except: pass return res _columns = { 'iniciativa_ids': fields.one2many('crm.lead', 'partner_id',\ 'Leads'), 'iniciativa_count': fields.function(_iniciativa_count, string='Lead', type='integer'), }