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.

40 lines
1.7 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2016 Odoo SA <https://www.odoo.com>
  3. # Copyright 2018 Therp BV <http://therp.nl>
  4. # Copyright 2018 Eficent <http://www.eficent.com>
  5. # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
  6. from odoo import api, models
  7. class CalendarEvent(models.Model):
  8. _inherit = 'calendar.event'
  9. @api.model
  10. def default_get(self, fields):
  11. if self.env.context.get('default_opportunity_id'):
  12. self = self.with_context(
  13. default_res_model_id=self.env.ref('crm.model_crm_lead').id,
  14. default_res_id=self.env.context['default_opportunity_id']
  15. )
  16. defaults = super(CalendarEvent, self).default_get(fields)
  17. # sync res_model / res_id to opportunity id (aka
  18. # creating meeting from lead chatter)
  19. if 'opportunity_id' not in defaults and defaults.get('res_id') and \
  20. (defaults.get('res_model') or defaults.get('res_model_id')):
  21. if (defaults.get('res_model') and
  22. defaults['res_model'] == 'crm.lead') or \
  23. (defaults.get('res_model_id') and self.env[
  24. 'ir.model'].sudo().browse(
  25. defaults['res_model_id']).model == 'crm.lead'):
  26. defaults['opportunity_id'] = defaults['res_id']
  27. return defaults
  28. def _compute_is_highlighted(self):
  29. super(CalendarEvent, self)._compute_is_highlighted()
  30. if self.env.context.get('active_model') == 'crm.lead':
  31. opportunity_id = self.env.context.get('active_id')
  32. for event in self:
  33. if event.opportunity_id.id == opportunity_id:
  34. event.is_highlighted = True