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.

103 lines
4.5 KiB

  1. # -*- encoding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # OpenERP, Open Source Management Solution
  5. # Copyright (c) 2011 Zikzakmedia S.L. (http://zikzakmedia.com) All Rights Reserved.
  6. # Copyright (c) 2012 Akretion (http://www.akretion.com)
  7. # @author: Jesús Martín <jmartin@zikzakmedia.com>
  8. # @author: Alexis de Lattre <alexis.delattre@akretion.com>
  9. #
  10. # This program is free software: you can redistribute it and/or modify
  11. # it under the terms of the GNU Affero General Public License as published by
  12. # the Free Software Foundation, either version 3 of the License, or
  13. # (at your option) any later version.
  14. #
  15. # This program is distributed in the hope that it will be useful,
  16. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. # GNU Affero General Public License for more details.
  19. #
  20. # You should have received a copy of the GNU Affero General Public License
  21. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. #
  23. ##############################################################################
  24. from osv import osv, fields
  25. # Lib to translate error messages
  26. from tools.translate import _
  27. class res_partner_address(osv.osv):
  28. _inherit = "res.partner.address"
  29. def dial(self, cr, uid, ids, phone_field='phone', context=None):
  30. '''
  31. This method open the phone call history when the phone click2dial
  32. button of asterisk_click2dial module is pressed
  33. :return the phone call history view of the partner
  34. '''
  35. if context is None:
  36. context = {}
  37. super(res_partner_address, self).dial(cr, uid, ids, phone_field=phone_field, context=context)
  38. return self.create_open_phonecall(cr, uid, ids, crm_categ='Outbound', context=context)
  39. def create_open_phonecall(self, cr, uid, ids, crm_categ, context=None):
  40. if context is None:
  41. context = {}
  42. crm_phonecall_id = self.create_phonecall(cr, uid, ids, crm_categ=crm_categ, context=context)
  43. partner = self.browse(cr, uid, ids[0], context=context).partner_id
  44. return {
  45. 'name': partner.name,
  46. 'domain': "[('partner_address_id.partner_id.id', '=', %s)]" % partner.id,
  47. 'res_model': 'crm.phonecall',
  48. 'res_id': [crm_phonecall_id],
  49. 'view_type': 'form',
  50. 'view_mode': 'form,tree',
  51. 'type': 'ir.actions.act_window',
  52. 'nodestroy': True,
  53. 'target': 'current',
  54. 'context': context,
  55. }
  56. def create_phonecall(self, cr, uid, ids, crm_categ='Outbound', context=None):
  57. '''
  58. This method creates a phone call history when the phone click2dial
  59. button of asterisk_click2dial module is pressed and opens it.
  60. :return True
  61. '''
  62. if context is None:
  63. context = {}
  64. crm_phonecall_obj = self.pool.get('crm.phonecall')
  65. partner_address = self.browse(cr, uid, ids[0], context=context)
  66. categ_ids = self.pool.get('crm.case.categ').search(cr, uid, [('name','=',crm_categ)], context={'lang': 'en_US'})
  67. case_section_ids = self.pool.get('crm.case.section').search(cr, uid, [('member_ids', 'in', uid)], context=context)
  68. values = {
  69. 'name': "CRM Call", # TODO check name
  70. 'partner_id': partner_address.partner_id and partner_address.partner_id.id or False,
  71. 'partner_address_id': partner_address.id,
  72. 'partner_phone': partner_address.phone,
  73. 'partner_contact': partner_address.name,
  74. 'partner_mobile': partner_address.mobile,
  75. 'user_id': uid,
  76. 'categ_id': categ_ids and categ_ids[0] or False,
  77. 'section_id': case_section_ids and case_section_ids[0] or False,
  78. }
  79. crm_phonecall_id = crm_phonecall_obj.create(cr, uid, values, context=context)
  80. return crm_phonecall_id
  81. res_partner_address()
  82. class wizard_open_calling_partner(osv.osv_memory):
  83. _inherit = "wizard.open.calling.partner"
  84. def create_incoming_phonecall(self, cr, uid, ids, crm_categ, context=None):
  85. '''Started by button on 'open calling partner wizard'''
  86. partner_address_id = self.browse(cr, uid, ids[0], context=context).partner_address_id.id
  87. action = self.pool.get('res.partner.address').create_open_phonecall(cr, uid, [partner_address_id], crm_categ='Inbound', context=context)
  88. action['nodestroy'] = False
  89. return action
  90. wizard_open_calling_partner()