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.

54 lines
2.0 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2012-2018 Akretion France
  3. # @author: Alexis de Lattre <alexis.delattre@akretion.com>
  4. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  5. from odoo import api, models
  6. import logging
  7. logger = logging.getLogger(__name__)
  8. try:
  9. import phonenumbers
  10. except ImportError:
  11. logger.debug('Cannot import phonenumbers lib.')
  12. class WizardCreateCrmPhonecall(models.TransientModel):
  13. _name = "wizard.create.crm.phonecall"
  14. _description = "Propose to create a phone call in CRM"
  15. def button_create_outgoing_phonecall(self):
  16. self.ensure_one()
  17. return self._create_open_crm_phonecall('outbound')
  18. @api.model
  19. def _create_open_crm_phonecall(self, direction='outbound'):
  20. teams = self.env['crm.team'].search(
  21. [('member_ids', 'in', self._uid)])
  22. action_ctx = self.env.context.copy()
  23. action_ctx.update({
  24. 'default_direction': direction,
  25. 'default_team_id': teams and teams[0].id or False,
  26. })
  27. if self.env.context.get('click2dial_model') == 'res.partner':
  28. partner_id = self.env.context.get('click2dial_id')
  29. action_ctx['default_partner_id'] = partner_id
  30. elif self.env.context.get('click2dial_model') == 'crm.lead':
  31. lead_id = self.env.context.get('click2dial_id')
  32. action_ctx['default_opportunity_id'] = lead_id
  33. parsed_num = phonenumbers.parse(self.env.context.get('phone_number'))
  34. number_type = phonenumbers.number_type(parsed_num)
  35. if number_type == 1:
  36. action_ctx['default_partner_mobile'] =\
  37. self.env.context.get('phone_number')
  38. else:
  39. action_ctx['default_partner_phone'] =\
  40. self.env.context.get('phone_number')
  41. action = self.env['ir.actions.act_window'].for_xml_id(
  42. 'crm_phone', 'crm_phonecall_action')
  43. action.update({
  44. 'view_mode': 'form,tree,calendar',
  45. 'views': False,
  46. 'context': action_ctx,
  47. })
  48. return action