From 1341d52540d7bd30ef1c98adbd6d188db4cafe98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 16 Nov 2021 16:45:18 +0000 Subject: [PATCH] [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.`` 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.`` 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 --- addons/crm/tests/test_crm_lead_lost.py | 7 +++---- addons/crm/wizard/crm_lead_lost.py | 14 +++++++------- addons/crm/wizard/crm_lead_lost_views.xml | 4 ++-- addons/mail/models/mail_thread.py | 23 +++++++++++++++++++++-- 4 files changed, 33 insertions(+), 15 deletions(-) diff --git a/addons/crm/tests/test_crm_lead_lost.py b/addons/crm/tests/test_crm_lead_lost.py index e7dd92669fc..33d5f38ea41 100644 --- a/addons/crm/tests/test_crm_lead_lost.py +++ b/addons/crm/tests/test_crm_lead_lost.py @@ -92,7 +92,7 @@ class TestLeadConvert(crm_common.TestCrmCommon): self.assertEqual(lead.probability, 0) self.assertEqual(lead.lost_reason_id, self.lost_reason) # check messages - self.assertEqual(len(lead.message_ids), 3, 'Should have 3 messages: creation, lost, and log') + self.assertEqual(len(lead.message_ids), 2, 'Should have 2 messages: creation, lost with log') lost_message = lead.message_ids.filtered(lambda msg: msg.subtype_id == self.env.ref('crm.mt_lead_lost')) self.assertTrue(lost_message) self.assertTracking( @@ -101,9 +101,8 @@ class TestLeadConvert(crm_common.TestCrmCommon): ('lost_reason_id', 'many2one', False, self.lost_reason) ] ) - note_message = lead.message_ids.filtered(lambda msg: msg.subtype_id == self.env.ref('mail.mt_note')) - self.assertTrue(note_message) - self.assertEqual(note_message.body, '

I cannot find it. It was in my closet and pouf, disappeared.

') + self.assertIn('

I cannot find it. It was in my closet and pouf, disappeared.

', lost_message.body, + 'Feedback should be included directly within tracking message') @users('user_sales_salesman') @mute_logger('odoo.addons.base.models') diff --git a/addons/crm/wizard/crm_lead_lost.py b/addons/crm/wizard/crm_lead_lost.py index 66b36754c6f..0db92f5a739 100644 --- a/addons/crm/wizard/crm_lead_lost.py +++ b/addons/crm/wizard/crm_lead_lost.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from odoo import fields, models +from odoo import fields, models, _ from odoo.tools.mail import is_html_empty @@ -18,12 +18,12 @@ class CrmLeadLost(models.TransientModel): def action_lost_reason_apply(self): self.ensure_one() leads = self.env['crm.lead'].browse(self.env.context.get('active_ids')) - res = leads.action_set_lost(lost_reason_id=self.lost_reason_id.id) if not is_html_empty(self.lost_feedback): - leads._message_log_batch( - bodies=dict( - (lead.id, self.lost_feedback) - for lead in leads), - subject=False, + leads._track_set_log_message( + '

%s:

%s
' % ( + _('Lost Comment'), + self.lost_feedback + ) ) + res = leads.action_set_lost(lost_reason_id=self.lost_reason_id.id) return res diff --git a/addons/crm/wizard/crm_lead_lost_views.xml b/addons/crm/wizard/crm_lead_lost_views.xml index c6ca6b23aca..b046443d5e8 100644 --- a/addons/crm/wizard/crm_lead_lost_views.xml +++ b/addons/crm/wizard/crm_lead_lost_views.xml @@ -5,10 +5,10 @@ crm.lead.lost
- + - +