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.

80 lines
3.2 KiB

  1. # -*- encoding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # CRM Phone module for Odoo
  5. # Copyright (c) 2012-2015 Akretion (http://www.akretion.com)
  6. # @author: Alexis de Lattre <alexis.delattre@akretion.com>
  7. #
  8. # This program is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU Affero General Public License as published
  10. # by the Free Software Foundation, either version 3 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU Affero General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU Affero General Public License
  19. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. #
  21. ##############################################################################
  22. from openerp import models, api, _
  23. import logging
  24. _logger = logging.getLogger(__name__)
  25. try:
  26. import phonenumbers
  27. except ImportError:
  28. _logger.debug('Cannot import phonenumbers')
  29. class wizard_create_crm_phonecall(models.TransientModel):
  30. _name = "wizard.create.crm.phonecall"
  31. @api.multi
  32. def button_create_outgoing_phonecall(self):
  33. self.ensure_one()
  34. return self._create_open_crm_phonecall(crm_categ='Outbound')
  35. @api.model
  36. def _create_open_crm_phonecall(self, crm_categ):
  37. categ = self.with_context(lang='en_US').env['crm.case.categ'].search(
  38. [('name', '=', crm_categ)])
  39. case_section = self.env['crm.case.section'].search(
  40. [('member_ids', 'in', self._uid)])
  41. action_ctx = self.env.context.copy()
  42. action_ctx.update({
  43. 'default_categ_id': categ and categ[0].id or False,
  44. 'default_section_id':
  45. case_section and case_section[0].id or False,
  46. })
  47. domain = False
  48. if self.env.context.get('click2dial_model') == 'res.partner':
  49. partner_id = self.env.context.get('click2dial_id')
  50. action_ctx['default_partner_id'] = partner_id
  51. domain = [('partner_id', '=', partner_id)]
  52. elif self.env.context.get('click2dial_model') == 'crm.lead':
  53. lead_id = self.env.context.get('click2dial_id')
  54. action_ctx['default_opportunity_id'] = lead_id
  55. domain = [('opportunity_id', '=', lead_id)]
  56. parsed_num = phonenumbers.parse(self.env.context.get('phone_number'))
  57. number_type = phonenumbers.number_type(parsed_num)
  58. if number_type == 1:
  59. action_ctx['default_partner_mobile'] =\
  60. self.env.context.get('phone_number')
  61. else:
  62. action_ctx['default_partner_phone'] =\
  63. self.env.context.get('phone_number')
  64. return {
  65. 'name': _('Phone Call'),
  66. 'domain': domain,
  67. 'res_model': 'crm.phonecall',
  68. 'view_mode': 'form,tree',
  69. 'type': 'ir.actions.act_window',
  70. 'nodestroy': False, # close the pop-up wizard after action
  71. 'target': 'current',
  72. 'context': action_ctx,
  73. }