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.

90 lines
3.4 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.osv import osv, fields
  26. # Lib to translate error messages
  27. from openerp.tools.translate import _
  28. class res_partner(osv.osv):
  29. _name = 'res.partner'
  30. _inherit = ['res.partner', 'asterisk.common']
  31. def action_dial(self, cr, uid, ids, context=None):
  32. '''
  33. This method open the phone call history when the phone click2dial
  34. button of asterisk_click2dial module is pressed
  35. :return the phone call history view of the partner
  36. '''
  37. if context is None:
  38. context = {}
  39. super(res_partner, self).action_dial(cr, uid, ids, context=context)
  40. user = self.pool['res.users'].browse(cr, uid, uid, context=context)
  41. context['partner_id'] = ids[0]
  42. action_start_wizard = {
  43. 'name': 'Create phone call in CRM',
  44. 'type': 'ir.actions.act_window',
  45. 'res_model': 'wizard.create.crm.phonecall',
  46. 'view_type': 'form',
  47. 'view_mode': 'form',
  48. 'nodestroy': True,
  49. 'target': 'new',
  50. 'context': context,
  51. }
  52. if user.context_propose_creation_crm_call:
  53. return action_start_wizard
  54. else:
  55. return True
  56. class res_users(osv.osv):
  57. _inherit = "res.users"
  58. _columns = {
  59. # Field name starts with 'context_' to allow modification by the user
  60. # in his preferences, cf server-61/openerp/addons/base/res/res_users.py
  61. # line 377 in "def write" of "class users"
  62. 'context_propose_creation_crm_call': fields.boolean('Propose to create a call in CRM after a click2dial'),
  63. }
  64. _defaults = {
  65. 'context_propose_creation_crm_call': True,
  66. }
  67. class crm_lead(osv.osv):
  68. _name = 'crm.lead'
  69. _inherit = ['crm.lead', 'asterisk.common']
  70. def create(self, cr, uid, vals, context=None):
  71. vals_reformated = self._generic_reformat_phonenumbers(cr, uid, vals, context=context)
  72. return super(crm_lead, self).create(cr, uid, vals_reformated, context=context)
  73. def write(self, cr, uid, ids, vals, context=None):
  74. vals_reformated = self._generic_reformat_phonenumbers(cr, uid, vals, context=context)
  75. return super(crm_lead, self).write(cr, uid, ids, vals_reformated, context=context)