mail_activity.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. from odoo import models, fields, tools, _
  4. from odoo.tools import is_html_empty
  5. class MailActivity(models.Model):
  6. _inherit = "mail.activity"
  7. calendar_event_id = fields.Many2one('calendar.event', string="Calendar Meeting", ondelete='cascade')
  8. def action_create_calendar_event(self):
  9. self.ensure_one()
  10. action = self.env["ir.actions.actions"]._for_xml_id("calendar.action_calendar_event")
  11. action['context'] = {
  12. 'default_activity_type_id': self.activity_type_id.id,
  13. 'default_res_id': self.env.context.get('default_res_id'),
  14. 'default_res_model': self.env.context.get('default_res_model'),
  15. 'default_name': self.summary or self.res_name,
  16. 'default_description': self.note if not is_html_empty(self.note) else '',
  17. 'default_activity_ids': [(6, 0, self.ids)],
  18. }
  19. return action
  20. def _action_done(self, feedback=False, attachment_ids=False):
  21. if feedback:
  22. for event in self.calendar_event_id:
  23. description = event.description
  24. description = '%s<br />%s' % (
  25. description if not tools.is_html_empty(description) else '',
  26. _('Feedback: %(feedback)s', feedback=tools.plaintext2html(feedback)) if feedback else '',
  27. )
  28. event.write({'description': description})
  29. return super(MailActivity, self)._action_done(feedback=feedback, attachment_ids=attachment_ids)
  30. def unlink_w_meeting(self):
  31. events = self.mapped('calendar_event_id')
  32. res = self.unlink()
  33. events.unlink()
  34. return res