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.

104 lines
4.0 KiB

  1. # -*- encoding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # CRM Phone module for Odoo
  5. # Copyright (C) 2010-2015 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. class number_not_found(orm.TransientModel):
  24. _inherit = "number.not.found"
  25. _columns = {
  26. 'to_update_lead_id': fields.many2one(
  27. 'crm.lead', 'Lead to Update',
  28. domain=[('type', '=', 'lead')],
  29. help="Lead on which the phone number will be written"),
  30. 'current_lead_phone': fields.related(
  31. 'to_update_lead_id', 'phone', type='char',
  32. relation='crm.lead', string='Current Phone', readonly=True),
  33. 'current_lead_mobile': fields.related(
  34. 'to_update_lead_id', 'mobile', type='char',
  35. relation='crm.lead', string='Current Mobile', readonly=True),
  36. }
  37. def create_lead(self, cr, uid, ids, context=None):
  38. '''Function called by the related button of the wizard'''
  39. if context is None:
  40. context = {}
  41. wiz = self.browse(cr, uid, ids[0], context=context)
  42. action = {
  43. 'name': _('Create New Lead'),
  44. 'type': 'ir.actions.act_window',
  45. 'res_model': 'crm.lead',
  46. 'view_mode': 'form,tree',
  47. 'domain': ['|', ('type', '=', 'lead'), ('type', '=', False)],
  48. 'nodestroy': False,
  49. 'target': 'current',
  50. 'context': {
  51. 'default_%s' % wiz.number_type: wiz.e164_number,
  52. 'default_type': 'lead',
  53. 'stage_type': 'lead',
  54. 'needaction_menu_ref': 'crm.menu_crm_opportunities',
  55. },
  56. }
  57. return action
  58. def update_lead(self, cr, uid, ids, context=None):
  59. wiz = self.browse(cr, uid, ids[0], context=context)
  60. if not wiz.to_update_lead_id:
  61. raise orm.except_orm(
  62. _('Error:'),
  63. _("Select the Lead to Update."))
  64. self.pool['crm.lead'].write(
  65. cr, uid, wiz.to_update_lead_id.id,
  66. {wiz.number_type: wiz.e164_number}, context=context)
  67. action = {
  68. 'name': _('Lead: %s' % wiz.to_update_lead_id.name),
  69. 'type': 'ir.actions.act_window',
  70. 'res_model': 'crm.lead',
  71. 'view_mode': 'form,tree',
  72. 'nodestroy': False,
  73. 'target': 'current',
  74. 'res_id': wiz.to_update_lead_id.id,
  75. 'context': {
  76. 'stage_type': 'lead',
  77. 'needaction_menu_ref': 'crm.menu_crm_opportunities',
  78. },
  79. }
  80. return action
  81. def onchange_to_update_lead(
  82. self, cr, uid, ids, to_update_lead_id, context=None):
  83. res = {'value': {}}
  84. if to_update_lead_id:
  85. to_update_lead = self.pool['crm.lead'].browse(
  86. cr, uid, to_update_lead_id, context=context)
  87. res['value'].update({
  88. 'current_lead_phone': to_update_lead.phone,
  89. 'current_lead_mobile': to_update_lead.mobile,
  90. })
  91. else:
  92. res['value'].update({
  93. 'current_lead_phone': False,
  94. 'current_lead_mobile': False,
  95. })
  96. return res