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.

117 lines
4.3 KiB

  1. # -*- encoding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # CRM phone module for Odoo/OpenERP
  5. # Copyright (c) 2012-2014 Akretion (http://www.akretion.com)
  6. # @author: Alexis de Lattre <alexis.delattre@akretion.com>
  7. #
  8. # This program is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU Affero General Public License as published
  10. # by the Free Software Foundation, either version 3 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU Affero General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU Affero General Public License
  19. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. #
  21. ##############################################################################
  22. from openerp import models, fields
  23. class CrmLead(models.Model):
  24. _name = 'crm.lead'
  25. _inherit = ['crm.lead', 'phone.common']
  26. _phone_fields = ['phone', 'mobile', 'fax']
  27. _phone_name_sequence = 20
  28. _country_field = 'country_id'
  29. _partner_field = None
  30. def create(self, cr, uid, vals, context=None):
  31. vals_reformated = self._generic_reformat_phonenumbers(
  32. cr, uid, None, vals, context=context)
  33. return super(CrmLead, self).create(
  34. cr, uid, vals_reformated, context=context)
  35. def write(self, cr, uid, ids, vals, context=None):
  36. vals_reformated = self._generic_reformat_phonenumbers(
  37. cr, uid, ids, vals, context=context)
  38. return super(CrmLead, self).write(
  39. cr, uid, ids, vals_reformated, context=context)
  40. def name_get(self, cr, uid, ids, context=None):
  41. if context is None:
  42. context = {}
  43. if context.get('callerid'):
  44. res = []
  45. if isinstance(ids, (int, long)):
  46. ids = [ids]
  47. for lead in self.browse(cr, uid, ids, context=context):
  48. if lead.partner_name and lead.contact_name:
  49. name = u'%s (%s)' % (lead.contact_name, lead.partner_name)
  50. elif lead.partner_name:
  51. name = lead.partner_name
  52. elif lead.contact_name:
  53. name = lead.contact_name
  54. else:
  55. name = lead.name
  56. res.append((lead.id, name))
  57. return res
  58. else:
  59. return super(CrmLead, self).name_get(
  60. cr, uid, ids, context=context)
  61. class CrmPhonecall(models.Model):
  62. _name = 'crm.phonecall'
  63. _inherit = ['crm.phonecall', 'phone.common']
  64. _phone_fields = ['partner_phone', 'partner_mobile']
  65. _country_field = None
  66. _partner_field = 'partner_id'
  67. def create(self, cr, uid, vals, context=None):
  68. vals_reformated = self._generic_reformat_phonenumbers(
  69. cr, uid, None, vals, context=context)
  70. return super(CrmPhonecall, self).create(
  71. cr, uid, vals_reformated, context=context)
  72. def write(self, cr, uid, ids, vals, context=None):
  73. vals_reformated = self._generic_reformat_phonenumbers(
  74. cr, uid, ids, vals, context=context)
  75. return super(CrmPhonecall, self).write(
  76. cr, uid, ids, vals_reformated, context=context)
  77. class PhoneCommon(models.AbstractModel):
  78. _inherit = 'phone.common'
  79. def _get_phone_fields(self, cr, uid, context=None):
  80. res = super(PhoneCommon, self)._get_phone_fields(
  81. cr, uid, context=context)
  82. res.update({
  83. 'crm.lead': {
  84. 'phonefields': ['phone', 'mobile'],
  85. 'faxfields': ['fax'],
  86. 'get_name_sequence': 20,
  87. },
  88. 'crm.phonecall': {
  89. 'phonefields': ['partner_phone', 'partner_mobile'],
  90. },
  91. })
  92. return res
  93. class ResUsers(models.Model):
  94. _inherit = "res.users"
  95. # Field name starts with 'context_' to allow modification by the user
  96. # in his preferences, cf server/openerp/addons/base/res/res_users.py
  97. # in "def write()" of "class res_users(osv.osv)"
  98. context_propose_creation_crm_call = fields.Boolean(
  99. string='Propose to create a call in CRM after a click2dial',
  100. default=True)