You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.7 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2012-2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  4. from odoo import models, fields, api
  5. from odoo.addons.base_phone.fields import Phone, Fax
  6. class CrmLead(models.Model):
  7. _inherit = 'crm.lead'
  8. _phone_name_sequence = 20
  9. phone = Phone(country_field='country_id', partner_field='partner_id')
  10. mobile = Phone(country_field='country_id', partner_field='partner_id')
  11. fax = Fax(country_field='country_id', partner_field='partner_id')
  12. phonecall_ids = fields.One2many(
  13. 'crm.phonecall', 'opportunity_id', string='Phone Calls')
  14. phonecall_count = fields.Integer(
  15. compute='_count_phonecalls', string='Number of Phonecalls',
  16. readonly=True)
  17. @api.multi
  18. def name_get(self):
  19. if self._context.get('callerid'):
  20. res = []
  21. for lead in self:
  22. if lead.partner_name and lead.contact_name:
  23. name = u'%s (%s)' % (lead.contact_name, lead.partner_name)
  24. elif lead.partner_name:
  25. name = lead.partner_name
  26. elif lead.contact_name:
  27. name = lead.contact_name
  28. else:
  29. name = lead.name
  30. res.append((lead.id, name))
  31. return res
  32. else:
  33. return super(CrmLead, self).name_get()
  34. @api.multi
  35. @api.depends('phonecall_ids')
  36. def _count_phonecalls(self):
  37. cpo = self.env['crm.phonecall']
  38. for lead in self:
  39. try:
  40. lead.phonecall_count = cpo.search_count(
  41. [('opportunity_id', '=', lead.id)])
  42. except:
  43. lead.phonecall_count = 0