From e2d11fa2798ac12de439d77e1293d2dce0ff31e0 Mon Sep 17 00:00:00 2001 From: nounoubensebia Date: Fri, 2 Jul 2021 11:15:15 +0000 Subject: [PATCH] [IMP] [website_]crm: post crm.leads merge message using a full template MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use a template for merge post messages and clean how fields are displayed, notably by fixing the display format, and the field order. Indeed, previously posted lead merge message contained all fields in an alphabetical order, even ones that had empty values, which is not very user friendly in terms of display. Now, the displayed fields are determined and ordered by sections, which greatly improves understanding the various information. Please note however, that it has the downside of not including all fields anymore. The merged leads information are included in a "read more/read less" enabled block using the "data-o-mail-quote" feature to get a nice rendering and avoid cluttering the Odoo chatter UI. Within the sent mail however, the full text is directly visible when viewing through a mail client. Task-2451164 closes odoo/odoo#75946 Signed-off-by: Thibault Delavallee (tde) Co-authored-by: Aurélien Warnon --- addons/crm/__manifest__.py | 1 + addons/crm/data/crm_lead_merge_template.xml | 122 ++++++++++++++++++ addons/crm/models/crm_lead.py | 57 ++------ addons/crm/static/src/scss/crm.scss | 6 + addons/website_crm/__manifest__.py | 1 + .../data/crm_lead_merge_template.xml | 16 +++ .../__manifest__.py | 1 + .../data/crm_lead_merge_template.xml | 16 +++ 8 files changed, 171 insertions(+), 49 deletions(-) create mode 100644 addons/crm/data/crm_lead_merge_template.xml create mode 100644 addons/website_crm/data/crm_lead_merge_template.xml create mode 100644 addons/website_crm_partner_assign/data/crm_lead_merge_template.xml diff --git a/addons/crm/__manifest__.py b/addons/crm/__manifest__.py index 8841e81f3b7..55e0bcd8780 100644 --- a/addons/crm/__manifest__.py +++ b/addons/crm/__manifest__.py @@ -28,6 +28,7 @@ 'security/crm_security.xml', 'security/ir.model.access.csv', + 'data/crm_lead_merge_template.xml', 'data/crm_lead_prediction_data.xml', 'data/crm_lost_reason_data.xml', 'data/crm_stage_data.xml', diff --git a/addons/crm/data/crm_lead_merge_template.xml b/addons/crm/data/crm_lead_merge_template.xml new file mode 100644 index 00000000000..c081ada9ae9 --- /dev/null +++ b/addons/crm/data/crm_lead_merge_template.xml @@ -0,0 +1,122 @@ + + + + + + diff --git a/addons/crm/models/crm_lead.py b/addons/crm/models/crm_lead.py index d07c1d52581..ad463bbfc72 100644 --- a/addons/crm/models/crm_lead.py +++ b/addons/crm/models/crm_lead.py @@ -1234,54 +1234,6 @@ class Lead(models.Model): return data - def _merge_notify_get_merged_fields_message(self): - """ Generate the message body with the changed values - - :param fields : list of fields to track - :returns a list of message bodies for the corresponding leads - """ - bodies = [] - for lead in self: - title = "%s : %s\n" % (_('Merged opportunity') if lead.type == 'opportunity' else _('Merged lead'), lead.name) - body = [title] - _fields = self.env['ir.model.fields'].sudo().search([ - ('name', 'in', self._merge_get_fields()), - ('model_id.model', '=', lead._name), - ]) - for field in _fields: - value = getattr(lead, field.name, False) - if field.ttype == 'selection': - selections = lead.fields_get()[field.name]['selection'] - value = next((v[1] for v in selections if v[0] == value), value) - elif field.ttype == 'many2one': - if value: - value = value.sudo().display_name - elif field.ttype == 'many2many': - if value: - value = ','.join( - val.display_name - for val in value.sudo() - ) - body.append("%s: %s" % (field.field_description, value or '')) - bodies.append("
".join(body + ['
'])) - return bodies - - def _merge_notify(self, opportunities): - """ Post a message gathering merged leads/opps informations. It explains - which fields has been merged and their new value. `self` is the resulting - merge crm.lead record. - - :param opportunities: see ``_merge_dependences`` - """ - # TODO JEM: mail template should be used instead of fix body, subject text - self.ensure_one() - merge_message = _('Merged leads') if self.type == 'lead' else _('Merged opportunities') - subject = merge_message + ": " + ", ".join(opportunities.mapped('name')) - # message bodies - message_bodies = opportunities._merge_notify_get_merged_fields_message() - message_body = "\n\n".join(message_bodies) - return self.message_post(body=message_body, subject=subject) - def merge_opportunity(self, user_id=False, team_id=False, auto_unlink=True): """ Merge opportunities in one. Different cases of merge: - merge leads together = 1 new lead @@ -1325,7 +1277,14 @@ class Lead(models.Model): merged_data['team_id'] = team_id # log merge message - opportunities_head._merge_notify(opportunities_tail) + opportunities_head.message_post_with_view( + "crm.crm_lead_merge_summary", + values={ + "opportunities": opportunities_tail, + "is_html_empty": is_html_empty + }, + subtype_id=self.env.ref('mail.mt_note').id + ) # merge other data (mail.message, attachments, ...) from tail into head opportunities_head._merge_dependences(opportunities_tail) diff --git a/addons/crm/static/src/scss/crm.scss b/addons/crm/static/src/scss/crm.scss index e731507557b..c33a456d679 100644 --- a/addons/crm/static/src/scss/crm.scss +++ b/addons/crm/static/src/scss/crm.scss @@ -31,3 +31,9 @@ } } } + +.crm_lead_merge_summary { + blockquote { + font-style: normal; + } +} \ No newline at end of file diff --git a/addons/website_crm/__manifest__.py b/addons/website_crm/__manifest__.py index a36e9ffc065..25f1515d3e9 100644 --- a/addons/website_crm/__manifest__.py +++ b/addons/website_crm/__manifest__.py @@ -15,6 +15,7 @@ This module includes contact phone and mobile numbers validation.""", 'depends': ['website', 'crm'], 'data': [ 'security/ir.model.access.csv', + 'data/crm_lead_merge_template.xml', 'data/ir_actions_data.xml', 'data/ir_model_data.xml', 'views/crm_lead_views.xml', diff --git a/addons/website_crm/data/crm_lead_merge_template.xml b/addons/website_crm/data/crm_lead_merge_template.xml new file mode 100644 index 00000000000..3d13020c10e --- /dev/null +++ b/addons/website_crm/data/crm_lead_merge_template.xml @@ -0,0 +1,16 @@ + + + + + + diff --git a/addons/website_crm_partner_assign/__manifest__.py b/addons/website_crm_partner_assign/__manifest__.py index 2e22dafe4d2..aec9cf1600c 100644 --- a/addons/website_crm_partner_assign/__manifest__.py +++ b/addons/website_crm_partner_assign/__manifest__.py @@ -24,6 +24,7 @@ The automatic assignment is figured from the weight of partner levels and the ge 'depends': ['base_geolocalize', 'crm', 'account', 'website_partner', 'website_google_map', 'portal'], 'data': [ + 'data/crm_lead_merge_template.xml', 'data/crm_tag_data.xml', 'data/mail_template_data.xml', 'security/ir.model.access.csv', diff --git a/addons/website_crm_partner_assign/data/crm_lead_merge_template.xml b/addons/website_crm_partner_assign/data/crm_lead_merge_template.xml new file mode 100644 index 00000000000..5381daccace --- /dev/null +++ b/addons/website_crm_partner_assign/data/crm_lead_merge_template.xml @@ -0,0 +1,16 @@ + + + + + +