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.

124 lines
4.6 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. # -*- encoding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # Asterisk click2dial CRM module for OpenERP
  5. # Copyright (c) 2011 Zikzakmedia S.L. (http://zikzakmedia.com)
  6. # All Rights Reserved.
  7. # Copyright (c) 2012 Akretion (http://www.akretion.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
  13. # by 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 osv import osv, fields
  26. class wizard_create_crm_phonecall(osv.osv_memory):
  27. _name = "wizard.create.crm.phonecall"
  28. _columns = {
  29. # Stupid useless field, just to be able to use default_get()
  30. 'name': fields.char('Workaround', size=12),
  31. }
  32. def default_get(self, cr, uid, fields, context=None):
  33. res = {}
  34. self.pool.get('res.partner.address').dial(
  35. cr, uid, context.get('active_ids'),
  36. phone_field=context.get('phone_field'), context=context
  37. )
  38. return res
  39. def button_create_outgoing_phonecall(self, cr, uid, ids, context=None):
  40. partner_address = self.pool.get('res.partner.address').browse(
  41. cr, uid, context.get('active_id'), context=context
  42. )
  43. return self._create_open_crm_phonecall(
  44. cr, uid, partner_address, crm_categ='Outbound', context=context
  45. )
  46. def _create_open_crm_phonecall(self, cr, uid, partner_address,
  47. crm_categ='Outbound', context=None):
  48. if context is None:
  49. context = {}
  50. data_obj = self.pool.get('ir.model.data')
  51. data_section_ids = data_obj.search(cr, uid, [
  52. ('model', '=', 'crm.case.section'),
  53. ('module', '=', 'crm_configuration'),
  54. ('name', '=', 'section_support_phone')
  55. ], context=context)
  56. default_section_id = False
  57. if data_section_ids:
  58. default_section_id = data_obj.read(
  59. cr, uid, data_section_ids[0], ['res_id'], context=context
  60. )['res_id']
  61. if crm_categ == 'Outbound':
  62. crm_categ_xmlid = 'categ_phone2'
  63. elif crm_categ == 'Inbound':
  64. crm_categ_xmlid = 'categ_phone1'
  65. else:
  66. raise
  67. data_categ_ids = data_obj.search(cr, uid, [
  68. ('model', '=', 'crm.case.categ'),
  69. ('module', '=', 'crm_configuration'),
  70. ('name', '=', crm_categ_xmlid)
  71. ], context=context)
  72. default_categ_id = False
  73. if data_categ_ids:
  74. default_categ_id = data_obj.read(
  75. cr, uid, data_categ_ids[0], ['res_id'], context=context
  76. )['res_id']
  77. context.update({
  78. 'default_partner_id': (
  79. partner_address.partner_id
  80. and partner_address.partner_id.id
  81. or False
  82. ),
  83. 'default_partner_address_id': partner_address.id,
  84. 'default_partner_mobile': partner_address.mobile,
  85. 'default_partner_phone': partner_address.phone,
  86. 'default_section_id': default_section_id,
  87. 'default_categ_id': default_categ_id,
  88. 'default_user_id': uid,
  89. })
  90. data_view_ids = data_obj.search(cr, uid, [
  91. ('model', '=', 'ir.ui.view'),
  92. ('name', '=', 'crm_case_phone_form_view'),
  93. ('module', '=', 'crm_configuration')
  94. ], context=context)
  95. view_id = False
  96. if data_view_ids:
  97. view_id = data_obj.read(
  98. cr, uid, data_view_ids[0], ['res_id'], context=context
  99. )['res_id']
  100. return {
  101. 'name': partner_address.name,
  102. 'res_model': 'crm.case',
  103. 'view_type': 'form',
  104. 'view_mode': 'form,tree',
  105. 'view_id': [view_id],
  106. 'type': 'ir.actions.act_window',
  107. 'nodestroy': False, # close the pop-up wizard after action
  108. 'target': 'current',
  109. 'context': context,
  110. }
  111. wizard_create_crm_phonecall()