From 1f7d650da53785eecfe7262fec180ab469fa0163 Mon Sep 17 00:00:00 2001 From: "Nasreddin Boulif (bon)" Date: Mon, 28 Aug 2023 17:17:44 +0200 Subject: [PATCH] [FIX] mail: set name with default name instead of email Steps to reproduce: - Install `website_crm` module (for test purpose) - Go to `Contact Us` page on website - Edit the page - Change the submit button to create an opportunity instead, then save - Fill the form and save - Go back to CRM app and open the opportunity just created - In the chatter, try to send a message - Click on the checkbox of the suggested recipient (to enable it) Issue: - Email is displayed twice in the suggested recipients before click (instead of name + email or just email if same as name) - Email is set as default name in the opened dialog Cause: - Displaying email even if same as name - Not setting the fields with default values (received from `/mail/thread/data` rpc call) Solution: - Don't display email if same as name - For the suggested recipient label (next checkbox) : set name with default name value if name parsed from mail is same value as email - For the default values in the opened dialog: set default values with defaults received from `/mail/thread/data` rpc call opw-3470295 closes odoo/odoo#135951 X-original-commit: 02ef0425a1f4ae30d846f6c57489cdebc3b4bbad Signed-off-by: Nasreddin Boulif (bon) --- addons/mail/static/src/core/web/suggested_recipient.xml | 2 +- addons/mail/static/src/core/web/thread_service_patch.js | 7 +++++-- .../static/tests/composer/suggested_recipients_test.js | 4 ++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/addons/mail/static/src/core/web/suggested_recipient.xml b/addons/mail/static/src/core/web/suggested_recipient.xml index 1b2aaba0dca..cd9519602bd 100644 --- a/addons/mail/static/src/core/web/suggested_recipient.xml +++ b/addons/mail/static/src/core/web/suggested_recipient.xml @@ -6,7 +6,7 @@ diff --git a/addons/mail/static/src/core/web/thread_service_patch.js b/addons/mail/static/src/core/web/thread_service_patch.js index a4e87e17014..705ce189552 100644 --- a/addons/mail/static/src/core/web/thread_service_patch.js +++ b/addons/mail/static/src/core/web/thread_service_patch.js @@ -147,8 +147,11 @@ patch(ThreadService.prototype, { async insertSuggestedRecipients(thread, dataList) { const recipients = []; for (const data of dataList) { - const [partner_id, emailInfo, lang, reason] = data; - const [name, email] = emailInfo && parseEmail(emailInfo); + const [partner_id, emailInfo, lang, reason, customerInfo] = data; + let [name, email] = emailInfo ? parseEmail(emailInfo) : []; + if ((!name || name === email) && customerInfo?.name) { + name = customerInfo.name; + } recipients.push({ id: nextId++, name, diff --git a/addons/mail/static/tests/composer/suggested_recipients_test.js b/addons/mail/static/tests/composer/suggested_recipients_test.js index b36e8b034f1..1c3bc4cdb26 100644 --- a/addons/mail/static/tests/composer/suggested_recipients_test.js +++ b/addons/mail/static/tests/composer/suggested_recipients_test.js @@ -71,7 +71,7 @@ QUnit.test( }); await click("button", { text: "Send message" }); await contains(".o-mail-SuggestedRecipient", { - text: "john@test.be (john@test.be)", + text: "john@test.be", contains: ["input[type=checkbox]:checked"], }); await contains(".o-mail-SuggestedRecipient", { @@ -111,7 +111,7 @@ QUnit.test( }); await click("button", { text: "Send message" }); await contains(".o-mail-SuggestedRecipient", { - text: "john@test.be (john@test.be)", + text: "john@test.be", contains: ["input[type=checkbox]:checked"], }); await contains(".o-mail-SuggestedRecipient", {