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.8 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2010-2018 Akretion France
  3. # @author: Alexis de Lattre <alexis.delattre@akretion.com>
  4. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  5. from odoo import fields, models, _
  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 or Opportunity to Update',
  11. help="Lead or opportunity on which the phone number will be written.")
  12. current_lead_phone = fields.Char(
  13. related='to_update_lead_id.phone', readonly=True)
  14. current_lead_mobile = fields.Char(
  15. related='to_update_lead_id.mobile', readonly=True)
  16. def create_lead(self):
  17. '''Function called by the related button of the wizard'''
  18. self.ensure_one()
  19. action = self.env['ir.actions.act_window'].for_xml_id(
  20. 'crm', 'crm_lead_all_leads')
  21. form_views = [viewt for viewt in action['views'] if viewt[1] == 'form']
  22. action.update({
  23. 'view_mode': 'form',
  24. 'views': form_views,
  25. 'context': {
  26. 'default_%s' % self.number_type: self.e164_number,
  27. 'default_type': 'lead',
  28. 'search_default_type': 'lead',
  29. 'search_default_to_process': True,
  30. },
  31. })
  32. return action
  33. def create_opportunity(self):
  34. '''Function called by the related button of the wizard'''
  35. self.ensure_one()
  36. action = self.env['ir.actions.act_window'].for_xml_id(
  37. 'crm', 'crm_lead_opportunities')
  38. form_views = [viewt for viewt in action['views'] if viewt[1] == 'form']
  39. action.update({
  40. 'view_mode': 'form',
  41. 'views': form_views,
  42. 'context': {
  43. 'default_%s' % self.number_type: self.e164_number,
  44. 'default_type': 'opportunity',
  45. 'search_default_type': 'opportunity',
  46. },
  47. })
  48. return action
  49. def update_lead(self):
  50. self.ensure_one()
  51. if not self.to_update_lead_id:
  52. raise UserError(_("Select the Lead or Opportunity to Update."))
  53. self.to_update_lead_id.write({self.number_type: self.e164_number})
  54. if self.to_update_lead_id.type == 'lead':
  55. action = self.env['ir.actions.act_window'].for_xml_id(
  56. 'crm', 'crm_lead_all_leads')
  57. else:
  58. action = self.env['ir.actions.act_window'].for_xml_id(
  59. 'crm', 'crm_lead_opportunities')
  60. form_views = [viewt for viewt in action['views'] if viewt[1] == 'form']
  61. action.update({
  62. 'view_mode': 'form',
  63. 'views': form_views,
  64. 'res_id': self.to_update_lead_id.id,
  65. })
  66. return action