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.

98 lines
3.7 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.osv import orm
  23. class crm_lead(orm.Model):
  24. _name = 'crm.lead'
  25. _inherit = ['crm.lead', 'phone.common']
  26. def create(self, cr, uid, vals, context=None):
  27. vals_reformated = self._generic_reformat_phonenumbers(
  28. cr, uid, vals, context=context)
  29. return super(crm_lead, self).create(
  30. cr, uid, vals_reformated, context=context)
  31. def write(self, cr, uid, ids, vals, context=None):
  32. vals_reformated = self._generic_reformat_phonenumbers(
  33. cr, uid, vals, context=context)
  34. return super(crm_lead, self).write(
  35. cr, uid, ids, vals_reformated, context=context)
  36. def name_get(self, cr, uid, ids, context=None):
  37. if context is None:
  38. context = {}
  39. if context.get('callerid'):
  40. res = []
  41. if isinstance(ids, (int, long)):
  42. ids = [ids]
  43. for lead in self.browse(cr, uid, ids, context=context):
  44. if lead.partner_name and lead.contact_name:
  45. name = u'%s (%s)' % (lead.contact_name, lead.partner_name)
  46. elif lead.partner_name:
  47. name = lead.partner_name
  48. elif lead.contact_name:
  49. name = lead.contact_name
  50. else:
  51. name = lead.name
  52. res.append((lead.id, name))
  53. return res
  54. else:
  55. return super(crm_lead, self).name_get(
  56. cr, uid, ids, context=context)
  57. class crm_phonecall(orm.Model):
  58. _name = 'crm.phonecall'
  59. _inherit = ['crm.phonecall', 'phone.common']
  60. def create(self, cr, uid, vals, context=None):
  61. vals_reformated = self._generic_reformat_phonenumbers(
  62. cr, uid, vals, context=context)
  63. return super(crm_phonecall, self).create(
  64. cr, uid, vals_reformated, context=context)
  65. def write(self, cr, uid, ids, vals, context=None):
  66. vals_reformated = self._generic_reformat_phonenumbers(
  67. cr, uid, vals, context=context)
  68. return super(crm_phonecall, self).write(
  69. cr, uid, ids, vals_reformated, context=context)
  70. class phone_common(orm.AbstractModel):
  71. _inherit = 'phone.common'
  72. def _get_phone_fields(self, cr, uid, context=None):
  73. res = super(phone_common, self)._get_phone_fields(
  74. cr, uid, context=context)
  75. res.update({
  76. 'crm.lead': {
  77. 'phonefields': ['phone', 'mobile'],
  78. 'faxfields': ['fax'],
  79. 'get_name_sequence': 20,
  80. },
  81. 'crm.phonecall': {
  82. 'phonefields': ['partner_phone', 'partner_mobile'],
  83. },
  84. })
  85. return res