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.

110 lines
4.6 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. # Jesús Martín <jmartin@zikzakmedia.com>
  7. # $Id$
  8. #
  9. # This program is free software: you can redistribute it and/or modify
  10. # it under the terms of the GNU Affero General Public License as published by
  11. # the Free Software Foundation, either version 3 of the License, or
  12. # (at your option) any later version.
  13. #
  14. # This program is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. # GNU Affero General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU Affero General Public License
  20. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. #
  22. ##############################################################################
  23. from osv import osv, fields
  24. # Lib to translate error messages
  25. from tools.translate import _
  26. class res_partner_address(osv.osv):
  27. _name = "res.partner.address"
  28. _inherit = "res.partner.address"
  29. def action_dial_phone(self, cr, uid, ids, 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).action_dial_phone(cr, uid, ids, context)
  38. crm_phonecall_id = self.create_phonecall(cr, uid, ids, context)
  39. partner = self.browse(cr, uid, ids[0], context).partner_id
  40. return {
  41. 'name': partner.name,
  42. 'domain': "[('partner_address_id.partner_id.id', '=', %s)]" % partner.id,
  43. 'res_model': 'crm.phonecall',
  44. 'res_id': crm_phonecall_id,
  45. 'view_type': 'form',
  46. 'view_mode': 'form,tree',
  47. 'view_id': False,
  48. 'type': 'ir.actions.act_window',
  49. 'nodestroy': True,
  50. 'target': 'current',
  51. 'context': context,
  52. }
  53. def action_dial_mobile(self, cr, uid, ids, context=None):
  54. '''
  55. This method open the phone call history when the mobile click2dial
  56. button of asterisk_click2dial module is pressed
  57. :return the phone call history view of the partner
  58. '''
  59. if context is None:
  60. context = {}
  61. super(res_partner_address, self).action_dial_phone(cr, uid, ids, context)
  62. crm_phonecall_id = self.create_phonecall(cr, uid, ids, context)
  63. partner = self.browse(cr, uid, ids[0], context).partner_id
  64. return {
  65. 'name': partner.name,
  66. 'domain': "[('partner_address_id.partner_id.id', '=', %s)]" % partner.id,
  67. 'res_model': 'crm.phonecall',
  68. 'res_id': crm_phonecall_id,
  69. 'view_type': 'form',
  70. 'view_mode': 'form,tree',
  71. 'view_id': False,
  72. 'type': 'ir.actions.act_window',
  73. 'nodestroy': True,
  74. 'target': 'current',
  75. 'context': context,
  76. }
  77. def create_phonecall(self, cr, uid, ids, context = None):
  78. '''
  79. This method creates a phone call history when the phone click2dial
  80. button of asterisk_click2dial module is pressed and opens it.
  81. :return True
  82. '''
  83. if context is None:
  84. context = {}
  85. crm_phonecall_obj = self.pool.get('crm.phonecall')
  86. partner_address = self.browse(cr, uid, ids[0], context)
  87. categ_ids = self.pool.get('crm.case.categ').search(cr, uid, [('name','=','Outbound')], context={'lang': 'en_US'})
  88. case_seccion_ids = self.pool.get('crm.case.section').search(cr, uid, [('member_ids', 'in', uid)], context = context)
  89. values = {
  90. 'name': "",
  91. 'partner_id': partner_address.partner_id and partner_address.partner_id.id or False,
  92. 'partner_address_id': partner_address.id,
  93. 'partner_phone': partner_address.phone,
  94. 'partner_contact': partner_address.name,
  95. 'partner_mobile': partner_address.mobile,
  96. 'user_id': uid,
  97. 'categ_id': categ_ids and categ_ids[0] or False,
  98. 'section_id': case_seccion_ids and case_seccion_ids[0] or False,
  99. }
  100. crm_phonecall_id = crm_phonecall_obj.create(cr, uid, values, context)
  101. return crm_phonecall_id
  102. res_partner_address()