Files
odoo_source/addons/crm/wizard/crm_lead_lost.py
T
Thibault Delavallée 1341d52540 [IMP] mail, crm: allow to give a body to tracking
PURPOSE

Concatenate feedback message and tracking when marking a lead as lost. This
currently generates 2 consecutive message about the same change, having a
single one is better from an UI point of view.

SPECIFICATIONS

Allow to link a body to a value change tracking. Tracking is currently done
by accumulating changes in a structure (see ``env.cr.precommit.data`` usage
with ``mail.tracking.<name>`` key). In the end those values are used to
generate a message with tracking value and a subtype.

In this commit we allow to manually set a body used as a message for the
tracking message, adding a new ``mail.tracking.message.<name>`` key. It is
used when posting or logging the tracking message, simply propagated as body
to ``message_post`` or ``message_log``.

In crm we use this when losting a lead through the dedicated wizard. A bit
of custom html allows to have a nice display.

Task-2671709

Part-of: odoo/odoo#78648
2021-11-23 09:39:52 +00:00

30 lines
1023 B
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import fields, models, _
from odoo.tools.mail import is_html_empty
class CrmLeadLost(models.TransientModel):
_name = 'crm.lead.lost'
_description = 'Get Lost Reason'
lost_reason_id = fields.Many2one('crm.lost.reason', 'Lost Reason')
lost_feedback = fields.Html(
'Closing Note', sanitize=True,
help="Closing note logged in leads discussion history."
)
def action_lost_reason_apply(self):
self.ensure_one()
leads = self.env['crm.lead'].browse(self.env.context.get('active_ids'))
if not is_html_empty(self.lost_feedback):
leads._track_set_log_message(
'<div style="margin-bottom: 4px;"><p>%s:</p>%s<br /></div>' % (
_('Lost Comment'),
self.lost_feedback
)
)
res = leads.action_set_lost(lost_reason_id=self.lost_reason_id.id)
return res