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.

87 lines
4.1 KiB

  1. # -*- encoding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # Asterisk click2dial CRM module for OpenERP
  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 wizard_create_crm_phonecall(osv.osv_memory):
  28. _name = "wizard.create.crm.phonecall"
  29. def button_create_outgoing_phonecall(self, cr, uid, ids, context=None):
  30. partner_address = self.pool.get('res.partner.address').browse(cr, uid, context.get('partner_address_id'), context=context)
  31. return self._create_open_crm_phonecall(cr, uid, partner_address, crm_categ='Outbound', context=context)
  32. def _create_open_crm_phonecall(self, cr, uid, partner_address, crm_categ, context=None):
  33. if context is None:
  34. context = {}
  35. crm_phonecall_obj = self.pool.get('crm.phonecall')
  36. categ_ids = self.pool.get('crm.case.categ').search(cr, uid, [('name','=',crm_categ)], context={'lang': 'en_US'})
  37. case_section_ids = self.pool.get('crm.case.section').search(cr, uid, [('member_ids', 'in', uid)], context=context)
  38. values = {
  39. 'name': _('Call with') + ' ' + partner_address.name,
  40. 'partner_id': partner_address.partner_id and partner_address.partner_id.id or False,
  41. 'partner_address_id': partner_address.id,
  42. 'partner_phone': partner_address.phone,
  43. 'partner_contact': partner_address.name,
  44. 'partner_mobile': partner_address.mobile,
  45. 'user_id': uid,
  46. 'categ_id': categ_ids and categ_ids[0] or False,
  47. 'section_id': case_section_ids and case_section_ids[0] or False,
  48. # As we now ask the user if he wants to create a phone call in CRM,
  49. # we suppose that he will decide to create one only if the call
  50. # has succeeded, so we create it directly in 'Held' (done) state.
  51. # Otherwise, it would have been created in 'Todo' (open) state.
  52. 'state': 'done',
  53. }
  54. crm_phonecall_id = crm_phonecall_obj.create(cr, uid, values, context=context)
  55. return {
  56. 'name': partner_address.name,
  57. 'domain': [('partner_id', '=', partner_address.partner_id.id)],
  58. 'res_model': 'crm.phonecall',
  59. 'res_id': [crm_phonecall_id],
  60. 'view_type': 'form',
  61. 'view_mode': 'form,tree',
  62. 'type': 'ir.actions.act_window',
  63. 'nodestroy': False, # close the pop-up wizard after action
  64. 'target': 'current',
  65. 'context': context,
  66. }
  67. wizard_create_crm_phonecall()
  68. class wizard_open_calling_partner(osv.osv_memory):
  69. _inherit = "wizard.open.calling.partner"
  70. def create_incoming_phonecall(self, cr, uid, ids, crm_categ, context=None):
  71. '''Started by button on 'open calling partner wizard'''
  72. partner_address = self.browse(cr, uid, ids[0], context=context).partner_address_id
  73. action = self.pool.get('wizard.create.crm.phonecall')._create_open_crm_phonecall(cr, uid, partner_address, crm_categ='Inbound', context=context)
  74. return action
  75. wizard_open_calling_partner()