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.

93 lines
3.7 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2012-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. class CrmPhonecall(models.Model):
  7. _name = 'crm.phonecall'
  8. _inherit = ['mail.thread']
  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']._get_default_team_id())
  28. partner_id = fields.Many2one(
  29. 'res.partner', string='Contact', ondelete='cascade')
  30. partner_phone = Phone(string='Phone', partner_field='partner_id')
  31. partner_mobile = Phone(string='Mobile', partner_field='partner_id')
  32. priority = fields.Selection([
  33. ('0', 'Low'),
  34. ('1', 'Normal'),
  35. ('2', 'High')
  36. ], string='Priority', track_visibility='onchange', default='1')
  37. opportunity_id = fields.Many2one(
  38. 'crm.lead', string='Lead/Opportunity',
  39. ondelete='cascade', track_visibility='onchange')
  40. state = fields.Selection([
  41. ('open', 'To Do'),
  42. ('done', 'Held'),
  43. ('cancel', 'Cancelled'),
  44. ], string='Status', default='open', copy=False, required=True,
  45. track_visibility='onchange',
  46. help='The status is set to Confirmed, when a case is created.\n'
  47. 'When the call is over, the status is set to Held.\n'
  48. 'If the call is not applicable anymore, the status can be set to '
  49. 'Cancelled.')
  50. direction = fields.Selection([
  51. ('inbound', 'Inbound'),
  52. ('outbound', 'Outbound'),
  53. ], string='Type', required=True, default='outbound')
  54. @api.onchange('partner_id')
  55. def onchange_partner_id(self):
  56. if self.partner_id:
  57. self.partner_phone = self.partner_id.phone
  58. self.partner_mobile = self.partner_id.mobile
  59. @api.onchange('opportunity_id')
  60. def onchange_opportunity_id(self):
  61. if self.opportunity_id:
  62. self.partner_phone = self.opportunity_id.phone
  63. self.partner_mobile = self.opportunity_id.mobile
  64. self.team_id = self.opportunity_id.team_id.id
  65. self.partner_id = self.opportunity_id.partner_id.id
  66. @api.multi
  67. def schedule_another_call(self):
  68. self.ensure_one()
  69. cur_call = self[0]
  70. ctx = self._context.copy()
  71. ctx.update({
  72. 'default_date': False,
  73. 'default_partner_id': cur_call.partner_id.id,
  74. 'default_opportunity_id': cur_call.opportunity_id.id,
  75. 'default_direction': 'outbound',
  76. 'default_partner_phone': cur_call.partner_phone,
  77. 'default_partner_mobile': cur_call.partner_mobile,
  78. })
  79. action = {
  80. 'name': _('Phone Call'),
  81. 'type': 'ir.actions.act_window',
  82. 'res_model': 'crm.phonecall',
  83. 'view_mode': 'form,tree,calendar',
  84. 'context': ctx,
  85. }
  86. return action