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.3 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. # TODO : crm.phonecall : doesn't exist any more... what is the replacement ?
  7. class WizardCreateCrmPhonecall(models.TransientModel):
  8. _name = "wizard.create.crm.phonecall"
  9. @api.multi
  10. def button_create_outgoing_phonecall(self):
  11. self.ensure_one()
  12. return self._create_open_crm_phonecall(crm_categ='Outbound')
  13. @api.model
  14. def _create_open_crm_phonecall(self, crm_categ):
  15. categ = self.with_context(lang='en_US').env['crm.case.categ'].search(
  16. [('name', '=', crm_categ)])
  17. case_section = self.env['crm.case.section'].search(
  18. [('member_ids', 'in', self._uid)])
  19. action_ctx = self.env.context.copy()
  20. action_ctx.update({
  21. 'default_categ_id': categ and categ[0].id or False,
  22. 'default_section_id':
  23. case_section and case_section[0].id or False,
  24. })
  25. domain = False
  26. if self.env.context.get('click2dial_model') == 'res.partner':
  27. partner_id = self.env.context.get('click2dial_id')
  28. action_ctx['default_partner_id'] = partner_id
  29. domain = [('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. domain = [('opportunity_id', '=', lead_id)]
  34. parsed_num = phonenumbers.parse(self.env.context.get('phone_number'))
  35. number_type = phonenumbers.number_type(parsed_num)
  36. if number_type == 1:
  37. action_ctx['default_partner_mobile'] =\
  38. self.env.context.get('phone_number')
  39. else:
  40. action_ctx['default_partner_phone'] =\
  41. self.env.context.get('phone_number')
  42. return {
  43. 'name': _('Phone Call'),
  44. 'type': 'ir.actions.act_window',
  45. 'res_model': 'crm.phonecall',
  46. 'domain': domain,
  47. 'view_mode': 'form,tree',
  48. 'nodestroy': False, # close the pop-up wizard after action
  49. 'target': 'current',
  50. 'context': action_ctx,
  51. }