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.

66 lines
2.8 KiB

  1. # -*- encoding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # Asterisk click2dial CRM module for OpenERP
  5. # Copyright (c) 2011 Zikzakmedia S.L. (http://zikzakmedia.com)
  6. # Copyright (c) 2012-2013 Akretion (http://www.akretion.com)
  7. # Copyright (C) 2013 Invitu <contact@invitu.com>
  8. # @author: Jesús Martín <jmartin@zikzakmedia.com>
  9. # @author: Alexis de Lattre <alexis.delattre@akretion.com>
  10. #
  11. # This program is free software: you can redistribute it and/or modify
  12. # it under the terms of the GNU Affero General Public License as published by
  13. # the Free Software Foundation, either version 3 of the License, or
  14. # (at your option) any later version.
  15. #
  16. # This program is distributed in the hope that it will be useful,
  17. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. # GNU Affero General Public License for more details.
  20. #
  21. # You should have received a copy of the GNU Affero General Public License
  22. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. #
  24. ##############################################################################
  25. from openerp.addons.base_status.base_stage import base_stage
  26. from openerp.osv import osv, fields
  27. # Lib required to print logs
  28. import logging
  29. # Lib to translate error messages
  30. from openerp.tools.translate import _
  31. # Lib for phone number reformating -> pip install phonenumbers
  32. import phonenumbers
  33. # Lib py-asterisk from http://code.google.com/p/py-asterisk/
  34. # We need a version which has this commit : http://code.google.com/p/py-asterisk/source/detail?r=8d0e1c941cce727c702582f3c9fcd49beb4eeaa4
  35. # so a version after Nov 20th, 2012
  36. from Asterisk import Manager
  37. _logger = logging.getLogger(__name__)
  38. class crm_claim(osv.osv):
  39. _name = 'crm.claim'
  40. _inherit = ['crm.claim', 'asterisk.common']
  41. def format_phonenumber_to_e164(self, cr, uid, ids, name, arg, context=None):
  42. return self.generic_phonenumber_to_e164(cr, uid, ids, [('partner_phone', 'partner_phone_e164')], context=context)
  43. _columns = {
  44. 'partner_phone_e164': fields.function(format_phonenumber_to_e164, type='char', size=64, string='Phone in E.164 format', readonly=True, multi="e164claim", store={
  45. 'crm.claim': (lambda self, cr, uid, ids, c={}: ids, ['partner_phone'], 10),
  46. }),
  47. }
  48. def create(self, cr, uid, vals, context=None):
  49. vals_reformated = self.generic_reformat_phonenumbers(cr, uid, vals, context=context)
  50. return super(crm_claim, self).create(cr, uid, vals_reformated, context=context)
  51. def write(self, cr, uid, ids, vals, context=None):
  52. vals_reformated = self.generic_reformat_phonenumbers(cr, uid, vals, context=context)
  53. return super(crm_claim, self).write(cr, uid, ids, vals_reformated, context=context)