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.

73 lines
3.1 KiB

  1. # -*- encoding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # CRM Phone module for Odoo
  5. # Copyright (c) 2012-2015 Akretion (http://www.akretion.com)
  6. # @author: Alexis de Lattre <alexis.delattre@akretion.com>
  7. #
  8. # This program is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU Affero General Public License as published
  10. # by the Free Software Foundation, either version 3 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU Affero General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU Affero General Public License
  19. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. #
  21. ##############################################################################
  22. from openerp import models, api, _
  23. import phonenumbers
  24. class wizard_create_crm_phonecall(models.TransientModel):
  25. _name = "wizard.create.crm.phonecall"
  26. @api.multi
  27. def button_create_outgoing_phonecall(self):
  28. self.ensure_one()
  29. return self._create_open_crm_phonecall(crm_categ='Outbound')
  30. @api.model
  31. def _create_open_crm_phonecall(self, crm_categ):
  32. categ = self.with_context(lang='en_US').env['crm.case.categ'].search(
  33. [('name', '=', crm_categ)])
  34. case_section = self.env['crm.case.section'].search(
  35. [('member_ids', 'in', self._uid)])
  36. action_ctx = self.env.context.copy()
  37. action_ctx.update({
  38. 'default_categ_id': categ and categ[0].id or False,
  39. 'default_section_id':
  40. case_section and case_section[0].id or False,
  41. })
  42. domain = False
  43. if self.env.context.get('click2dial_model') == 'res.partner':
  44. partner_id = self.env.context.get('click2dial_id')
  45. action_ctx['default_partner_id'] = partner_id
  46. domain = [('partner_id', '=', partner_id)]
  47. elif self.env.context.get('click2dial_model') == 'crm.lead':
  48. lead_id = self.env.context.get('click2dial_id')
  49. action_ctx['default_opportunity_id'] = lead_id
  50. domain = [('opportunity_id', '=', lead_id)]
  51. parsed_num = phonenumbers.parse(self.env.context.get('phone_number'))
  52. number_type = phonenumbers.number_type(parsed_num)
  53. if number_type == 1:
  54. action_ctx['default_partner_mobile'] =\
  55. self.env.context.get('phone_number')
  56. else:
  57. action_ctx['default_partner_phone'] =\
  58. self.env.context.get('phone_number')
  59. return {
  60. 'name': _('Phone Call'),
  61. 'domain': domain,
  62. 'res_model': 'crm.phonecall',
  63. 'view_mode': 'form,tree',
  64. 'type': 'ir.actions.act_window',
  65. 'nodestroy': False, # close the pop-up wizard after action
  66. 'target': 'current',
  67. 'context': action_ctx,
  68. }