Files
odoo_source/addons/calendar/models/mail_activity.py
T
Pierre-Yves Dufays a3d2336b17 [FIX] calendar: fix duplicate feedback in the chatter activity done note
How to reproduce:
- install crm
- open a lead
- create an activity call or meeting (and schedule it in the calendar)
- mark it as done with a feedback

The activity log in the chatter contains the feedback twice and shouldn't.

The problem was caused by the synchronization of the event description with the
related activities. When marking an activity as done, the event description is
updated with the feedback which in turn update the activity note with the
feedback. When logging the activity done in the chatter, the note and the
feedback are logged leading to a duplicate feedback. We solve this by first
logging the activity done in the chatter before updating the event description.

Task-3653088

closes odoo/odoo#158268

X-original-commit: 0156204e465bc7f86643152cfff4d1aa33fd6935
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2024-03-20 18:29:24 +00:00

52 lines
2.4 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import models, fields, tools, _
from odoo.tools import is_html_empty
class MailActivity(models.Model):
_inherit = "mail.activity"
calendar_event_id = fields.Many2one('calendar.event', string="Calendar Meeting", ondelete='cascade')
def action_create_calendar_event(self):
self.ensure_one()
action = self.env["ir.actions.actions"]._for_xml_id("calendar.action_calendar_event")
action['context'] = {
'default_activity_type_id': self.activity_type_id.id,
'default_res_id': self.env.context.get('default_res_id'),
'default_res_model': self.env.context.get('default_res_model'),
'default_name': self.summary or self.res_name,
'default_description': self.note if not is_html_empty(self.note) else '',
'default_activity_ids': [(6, 0, self.ids)],
'default_partner_ids': self.user_id.partner_id.ids,
'default_user_id': self.user_id.id,
'initial_date': self.date_deadline,
'default_calendar_event_id': self.calendar_event_id.id,
}
return action
def _action_done(self, feedback=False, attachment_ids=False):
events = self.calendar_event_id
# To avoid the feedback to be included in the activity note (due to the synchronization in event.write
# that updates the related activity note each time the event description is updated),
# when the activity is written as a note in the chatter in _action_done (leading to duplicate feedback),
# we call super before updating the description. As self is deleted in super, we load the related events before.
messages, activities = super(MailActivity, self)._action_done(feedback=feedback, attachment_ids=attachment_ids)
if feedback:
for event in events:
description = event.description
description = '%s<br />%s' % (
description if not tools.is_html_empty(description) else '',
_('Feedback: %(feedback)s', feedback=tools.plaintext2html(feedback)) if feedback else '',
)
event.write({'description': description})
return messages, activities
def unlink_w_meeting(self):
events = self.mapped('calendar_event_id')
res = self.unlink()
events.unlink()
return res