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.

103 lines
4.0 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2012-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 api, fields, models
  6. class CrmPhonecall(models.Model):
  7. _name = 'crm.phonecall'
  8. _inherit = ['mail.thread', 'phone.validation.mixin']
  9. _order = "id desc"
  10. # Restore the object that existed in v8
  11. # and doesn't exist in v9 community any more
  12. name = fields.Char(
  13. string='Call Summary', required=True, track_visibility='onchange')
  14. date = fields.Datetime(
  15. string='Date', track_visibility='onchange', copy=False,
  16. default=lambda self: fields.Datetime.now())
  17. description = fields.Text(string='Description', copy=False)
  18. company_id = fields.Many2one(
  19. 'res.company', string='Company',
  20. default=lambda self: self.env['res.company']._company_default_get(
  21. 'crm.phonecall'))
  22. user_id = fields.Many2one(
  23. 'res.users', string='Responsible', track_visibility='onchange',
  24. default=lambda self: self.env.user)
  25. team_id = fields.Many2one(
  26. 'crm.team', string='Sales Team', track_visibility='onchange',
  27. default=lambda self: self.env['crm.team'].sudo()._get_default_team_id(
  28. user_id=self.env.uid))
  29. partner_id = fields.Many2one(
  30. 'res.partner', string='Contact', ondelete='cascade')
  31. partner_phone = fields.Char(string='Phone')
  32. partner_mobile = fields.Char(string='Mobile')
  33. priority = fields.Selection([
  34. ('0', 'Low'),
  35. ('1', 'Normal'),
  36. ('2', 'High')
  37. ], string='Priority', track_visibility='onchange', default='1')
  38. opportunity_id = fields.Many2one(
  39. 'crm.lead', string='Lead/Opportunity',
  40. ondelete='cascade', track_visibility='onchange')
  41. state = fields.Selection([
  42. ('open', 'To Do'),
  43. ('done', 'Held'),
  44. ('cancel', 'Cancelled'),
  45. ], string='Status', default='open', copy=False, required=True,
  46. track_visibility='onchange',
  47. help='The status is set to Confirmed, when a case is created.\n'
  48. 'When the call is over, the status is set to Held.\n'
  49. 'If the call is not applicable anymore, the status can be set to '
  50. 'Cancelled.')
  51. direction = fields.Selection([
  52. ('inbound', 'Inbound'),
  53. ('outbound', 'Outbound'),
  54. ], string='Type', required=True, default='outbound')
  55. @api.onchange('partner_id')
  56. def onchange_partner_id(self):
  57. if self.partner_id:
  58. self.partner_phone = self.partner_id.phone
  59. self.partner_mobile = self.partner_id.mobile
  60. @api.onchange('opportunity_id')
  61. def onchange_opportunity_id(self):
  62. if self.opportunity_id:
  63. self.partner_phone = self.opportunity_id.phone
  64. self.partner_mobile = self.opportunity_id.mobile
  65. self.team_id = self.opportunity_id.team_id.id
  66. self.partner_id = self.opportunity_id.partner_id.id
  67. @api.onchange('partner_phone')
  68. def onchange_partner_phone(self):
  69. if self.partner_phone:
  70. self.partner_phone = self.phone_format(self.partner_phone)
  71. @api.onchange('partner_mobile')
  72. def onchange_partner_mobile(self):
  73. if self.partner_mobile:
  74. self.partner_mobile = self.phone_format(self.partner_mobile)
  75. def schedule_another_call(self):
  76. self.ensure_one()
  77. cur_call = self[0]
  78. ctx = self._context.copy()
  79. ctx.update({
  80. 'default_date': False,
  81. 'default_partner_id': cur_call.partner_id.id,
  82. 'default_opportunity_id': cur_call.opportunity_id.id,
  83. 'default_direction': 'outbound',
  84. 'default_partner_phone': cur_call.partner_phone,
  85. 'default_partner_mobile': cur_call.partner_mobile,
  86. })
  87. action = self.env['ir.actions.act_window'].for_xml_id(
  88. 'crm_phone', 'crm_phonecall_action')
  89. action.update({
  90. 'view_mode': 'form,tree,calendar',
  91. 'views': False,
  92. 'context': ctx,
  93. })
  94. return action