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.

57 lines
2.2 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. domain = False
  28. if self.env.context.get('click2dial_model') == 'res.partner':
  29. partner_id = self.env.context.get('click2dial_id')
  30. action_ctx['default_partner_id'] = partner_id
  31. domain = [('partner_id', 'child_of', partner_id)]
  32. elif self.env.context.get('click2dial_model') == 'crm.lead':
  33. lead_id = self.env.context.get('click2dial_id')
  34. action_ctx['default_opportunity_id'] = lead_id
  35. domain = [('opportunity_id', '=', lead_id)]
  36. parsed_num = phonenumbers.parse(self.env.context.get('phone_number'))
  37. number_type = phonenumbers.number_type(parsed_num)
  38. if number_type == 1:
  39. action_ctx['default_partner_mobile'] =\
  40. self.env.context.get('phone_number')
  41. else:
  42. action_ctx['default_partner_phone'] =\
  43. self.env.context.get('phone_number')
  44. action = self.env['ir.actions.act_window'].for_xml_id(
  45. 'crm_phone', 'crm_phonecall_action')
  46. action.update({
  47. 'domain': domain,
  48. 'view_mode': 'form,tree,calendar',
  49. 'context': action_ctx,
  50. })
  51. return action