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.

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