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.

58 lines
2.2 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2012-2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  4. from odoo import models, api, _
  5. import logging
  6. logger = logging.getLogger(__name__)
  7. try:
  8. import phonenumbers
  9. except ImportError:
  10. logger.debug('Cannot import phonenumbers lib.')
  11. class WizardCreateCrmPhonecall(models.TransientModel):
  12. _name = "wizard.create.crm.phonecall"
  13. @api.multi
  14. def button_create_outgoing_phonecall(self):
  15. self.ensure_one()
  16. return self._create_open_crm_phonecall('outbound')
  17. @api.model
  18. def _create_open_crm_phonecall(self, direction='outbound'):
  19. teams = self.env['crm.team'].search(
  20. [('member_ids', 'in', self._uid)])
  21. action_ctx = self.env.context.copy()
  22. action_ctx.update({
  23. 'default_direction': direction,
  24. 'default_team_id': teams and teams[0].id or False,
  25. })
  26. domain = False
  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. domain = [('partner_id', 'child_of', partner_id)]
  31. elif self.env.context.get('click2dial_model') == 'crm.lead':
  32. lead_id = self.env.context.get('click2dial_id')
  33. action_ctx['default_opportunity_id'] = lead_id
  34. domain = [('opportunity_id', '=', lead_id)]
  35. parsed_num = phonenumbers.parse(self.env.context.get('phone_number'))
  36. number_type = phonenumbers.number_type(parsed_num)
  37. if number_type == 1:
  38. action_ctx['default_partner_mobile'] =\
  39. self.env.context.get('phone_number')
  40. else:
  41. action_ctx['default_partner_phone'] =\
  42. self.env.context.get('phone_number')
  43. return {
  44. 'name': _('Phone Call'),
  45. 'type': 'ir.actions.act_window',
  46. 'res_model': 'crm.phonecall',
  47. 'domain': domain,
  48. 'view_mode': 'form,tree,calendar',
  49. 'nodestroy': False, # close the pop-up wizard after action
  50. 'target': 'current',
  51. 'context': action_ctx,
  52. }