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.

52 lines
2.1 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 openerp import models, api, _
  5. import phonenumbers
  6. class WizardCreateCrmPhonecall(models.TransientModel):
  7. _name = "wizard.create.crm.phonecall"
  8. @api.multi
  9. def button_create_outgoing_phonecall(self):
  10. self.ensure_one()
  11. return self._create_open_crm_phonecall('outbound')
  12. @api.model
  13. def _create_open_crm_phonecall(self, direction='outbound'):
  14. teams = self.env['crm.team'].search(
  15. [('member_ids', 'in', self._uid)])
  16. action_ctx = self.env.context.copy()
  17. action_ctx.update({
  18. 'default_direction': direction,
  19. 'default_team_id': teams and teams[0].id or False,
  20. })
  21. domain = False
  22. if self.env.context.get('click2dial_model') == 'res.partner':
  23. partner_id = self.env.context.get('click2dial_id')
  24. action_ctx['default_partner_id'] = partner_id
  25. domain = [('partner_id', 'child_of', partner_id)]
  26. elif self.env.context.get('click2dial_model') == 'crm.lead':
  27. lead_id = self.env.context.get('click2dial_id')
  28. action_ctx['default_opportunity_id'] = lead_id
  29. domain = [('opportunity_id', '=', lead_id)]
  30. parsed_num = phonenumbers.parse(self.env.context.get('phone_number'))
  31. number_type = phonenumbers.number_type(parsed_num)
  32. if number_type == 1:
  33. action_ctx['default_partner_mobile'] =\
  34. self.env.context.get('phone_number')
  35. else:
  36. action_ctx['default_partner_phone'] =\
  37. self.env.context.get('phone_number')
  38. return {
  39. 'name': _('Phone Call'),
  40. 'type': 'ir.actions.act_window',
  41. 'res_model': 'crm.phonecall',
  42. 'domain': domain,
  43. 'view_mode': 'form,tree,calendar',
  44. 'nodestroy': False, # close the pop-up wizard after action
  45. 'target': 'current',
  46. 'context': action_ctx,
  47. }