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
2.6 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2010-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, fields, api, _
  5. from openerp.exceptions import UserError
  6. class NumberNotFound(models.TransientModel):
  7. _inherit = "number.not.found"
  8. to_update_lead_id = fields.Many2one(
  9. 'crm.lead', string='Lead to Update',
  10. domain=[('type', '=', 'lead')],
  11. help="Lead on which the phone number will be written")
  12. current_lead_phone = fields.Char(
  13. related='to_update_lead_id.phone', string='Current Phone',
  14. readonly=True)
  15. current_lead_mobile = fields.Char(
  16. related='to_update_lead_id.mobile', string='Current Mobile',
  17. readonly=True)
  18. @api.multi
  19. def create_lead(self):
  20. '''Function called by the related button of the wizard'''
  21. self.ensure_one()
  22. action = {
  23. 'name': _('Create New Lead'),
  24. 'type': 'ir.actions.act_window',
  25. 'res_model': 'crm.lead',
  26. 'view_mode': 'form,tree',
  27. 'domain': ['|', ('type', '=', 'lead'), ('type', '=', False)],
  28. 'nodestroy': False,
  29. 'target': 'current',
  30. 'context': {
  31. 'default_%s' % self.number_type: self.e164_number,
  32. 'default_type': 'lead',
  33. 'stage_type': 'lead',
  34. 'needaction_menu_ref': 'crm.menu_crm_opportunities',
  35. },
  36. }
  37. return action
  38. @api.multi
  39. def update_lead(self):
  40. self.ensure_one()
  41. if not self.to_update_lead_id:
  42. raise UserError(_("Select the Lead to Update."))
  43. self.to_update_lead_id.write({self.number_type: self.e164_number})
  44. action = {
  45. 'name': _('Lead: %s' % self.to_update_lead_id.name),
  46. 'type': 'ir.actions.act_window',
  47. 'res_model': 'crm.lead',
  48. 'view_mode': 'form,tree',
  49. 'nodestroy': False,
  50. 'target': 'current',
  51. 'res_id': self.to_update_lead_id.id,
  52. 'context': {
  53. 'stage_type': 'lead',
  54. 'needaction_menu_ref': 'crm.menu_crm_opportunities',
  55. },
  56. }
  57. return action
  58. @api.onchange('to_update_lead_id')
  59. def onchange_to_update_lead(self):
  60. if self.to_update_lead_id:
  61. self.current_lead_phone = self.to_update_lead_id.phone
  62. self.current_lead_mobile = self.to_update_lead_id.mobile
  63. else:
  64. self.current_lead_phone = False
  65. self.current_lead_mobile = False