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.

74 lines
2.5 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 openerp import models, fields, api, _
  5. class CrmLead(models.Model):
  6. _name = 'crm.lead'
  7. _inherit = ['crm.lead', 'phone.common']
  8. _phone_fields = ['phone', 'mobile', 'fax']
  9. _phone_name_sequence = 20
  10. _country_field = 'country_id'
  11. _partner_field = None
  12. @api.model
  13. def create(self, vals):
  14. vals_reformated = self._reformat_phonenumbers_create(vals)
  15. return super(CrmLead, self).create(vals_reformated)
  16. @api.multi
  17. def write(self, vals):
  18. vals_reformated = self._reformat_phonenumbers_write(vals)
  19. return super(CrmLead, self).write(vals_reformated)
  20. def name_get(self, cr, uid, ids, context=None):
  21. if context is None:
  22. context = {}
  23. if context.get('callerid'):
  24. res = []
  25. if isinstance(ids, (int, long)):
  26. ids = [ids]
  27. for lead in self.browse(cr, uid, ids, context=context):
  28. if lead.partner_name and lead.contact_name:
  29. name = u'%s (%s)' % (lead.contact_name, lead.partner_name)
  30. elif lead.partner_name:
  31. name = lead.partner_name
  32. elif lead.contact_name:
  33. name = lead.contact_name
  34. else:
  35. name = lead.name
  36. res.append((lead.id, name))
  37. return res
  38. else:
  39. return super(CrmLead, self).name_get(
  40. cr, uid, ids, context=context)
  41. class ResUsers(models.Model):
  42. _inherit = "res.users"
  43. # Field name starts with 'context_' to allow modification by the user
  44. # in his preferences, cf server/openerp/addons/base/res/res_users.py
  45. # in "def write()" of "class res_users(osv.osv)"
  46. context_propose_creation_crm_call = fields.Boolean(
  47. string='Propose to create a call in CRM after a click2dial',
  48. default=True)
  49. class PhoneCommon(models.AbstractModel):
  50. _inherit = 'phone.common'
  51. @api.model
  52. def click2dial(self, erp_number):
  53. res = super(PhoneCommon, self).click2dial(erp_number)
  54. if (
  55. self.env.user.context_propose_creation_crm_call and
  56. self.env.context.get('click2dial_model')
  57. in ('res.partner', 'crm.lead')):
  58. res.update({
  59. 'action_name': _('Create Call in CRM'),
  60. 'action_model': 'wizard.create.crm.phonecall',
  61. })
  62. return res