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.

47 lines
1.7 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2012-2018 Akretion France
  3. # @author: Alexis de Lattre <alexis.delattre@akretion.com>
  4. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  5. from odoo import models, fields, api
  6. class CrmLead(models.Model):
  7. _inherit = 'crm.lead'
  8. _phone_name_sequence = 20
  9. _phone_name_fields = ['phone', 'mobile']
  10. phonecall_ids = fields.One2many(
  11. 'crm.phonecall', 'opportunity_id', string='Phone Calls')
  12. phonecall_count = fields.Integer(
  13. compute='_compute_phonecall_count', string='Number of Phonecalls',
  14. readonly=True)
  15. partner_address_mobile = fields.Char(
  16. string='Partner Contact Mobile', related='partner_id.mobile',
  17. readonly=True)
  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.depends('phonecall_ids')
  35. def _compute_phonecall_count(self):
  36. rg_res = self.env['crm.phonecall'].read_group(
  37. [('opportunity_id', 'in', self.ids)],
  38. ['opportunity_id'], ['opportunity_id'])
  39. for rg_re in rg_res:
  40. lead = self.browse(rg_re['opportunity_id'][0])
  41. lead.phonecall_count = rg_re['opportunity_id_count']