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.

105 lines
4.0 KiB

  1. # -*- encoding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # Asterisk Click2dial module for OpenERP
  5. # Copyright (C) 2010-2013 Alexis de Lattre <alexis@via.ecp.fr>
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Affero General Public License as
  9. # published by the Free Software Foundation, either version 3 of the
  10. # License, or (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. ##############################################################################
  21. from openerp.osv import orm, fields
  22. from openerp.tools.translate import _
  23. import phonenumbers
  24. class number_not_found(orm.TransientModel):
  25. _inherit = "number.not.found"
  26. _columns = {
  27. 'to_update_lead_id': fields.many2one(
  28. 'crm.lead', 'Lead to Update',
  29. domain=[('type', '=', 'lead')],
  30. help="Lead on which the phone number will be written"),
  31. 'current_lead_phone': fields.related(
  32. 'to_update_lead_id', 'phone', type='char',
  33. relation='crm.lead', string='Current Phone', readonly=True),
  34. 'current_lead_mobile': fields.related(
  35. 'to_update_lead_id', 'mobile', type='char',
  36. relation='crm.lead', string='Current Mobile', readonly=True),
  37. }
  38. def create_lead(self, cr, uid, ids, context=None):
  39. '''Function called by the related button of the wizard'''
  40. if context is None:
  41. context = {}
  42. wiz = self.browse(cr, uid, ids[0], context=context)
  43. action = {
  44. 'name': _('Create New Lead'),
  45. 'type': 'ir.actions.act_window',
  46. 'res_model': 'crm.lead',
  47. 'view_mode': 'form,tree',
  48. 'domain': ['|', ('type', '=', 'lead'), ('type', '=', False)],
  49. 'nodestroy': False,
  50. 'target': 'current',
  51. 'context': {
  52. 'default_%s' % wiz.number_type: wiz.e164_number,
  53. 'default_type': 'lead',
  54. 'stage_type': 'lead',
  55. 'needaction_menu_ref': 'crm.menu_crm_opportunities',
  56. },
  57. }
  58. return action
  59. def update_lead(self, cr, uid, ids, context=None):
  60. wiz = self.browse(cr, uid, ids[0], context=context)
  61. if not wiz.to_update_lead_id:
  62. raise orm.except_orm(
  63. _('Error:'),
  64. _("Select the Lead to Update."))
  65. self.pool['crm.lead'].write(
  66. cr, uid, wiz.to_update_lead_id.id,
  67. {wiz.number_type: wiz.e164_number}, context=context)
  68. action = {
  69. 'name': _('Lead: %s' % wiz.to_update_lead_id.name),
  70. 'type': 'ir.actions.act_window',
  71. 'res_model': 'crm.lead',
  72. 'view_mode': 'form,tree',
  73. 'nodestroy': False,
  74. 'target': 'current',
  75. 'res_id': wiz.to_update_lead_id.id,
  76. 'context': {
  77. 'stage_type': 'lead',
  78. 'needaction_menu_ref': 'crm.menu_crm_opportunities',
  79. },
  80. }
  81. return action
  82. def onchange_to_update_lead(
  83. self, cr, uid, ids, to_update_lead_id, context=None):
  84. res = {'value': {}}
  85. if to_update_lead_id:
  86. to_update_lead = self.pool['crm.lead'].browse(
  87. cr, uid, to_update_lead_id, context=context)
  88. res['value'].update({
  89. 'current_lead_phone': to_update_lead.phone,
  90. 'current_lead_mobile': to_update_lead.mobile,
  91. })
  92. else:
  93. res['value'].update({
  94. 'current_lead_phone': False,
  95. 'current_lead_mobile': False,
  96. })
  97. return res