From 0d1a074854ac6502dc462a871d038e962f2c3fd0 Mon Sep 17 00:00:00 2001 From: "Abdelouahab (abla)" Date: Wed, 8 Feb 2023 14:06:27 +0000 Subject: [PATCH] [FIX] mail: uncheck recipient without partner MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To reproduce ============ - on website add or edit **contact us** form to create a task on a project - fill the form from Incognito - on project -> the created task : try to send message on chatter - you will find the email used when filling the form with possibilty to check it as receiver - check the box, a dialog will open to create a Partner for this email - close the dialog without modifying anything Problem ======= the checkbox will remain checked, but when you send a message no email will be sent Solution ======== as stated in this comment https://github.com/odoo/odoo/blob/de1f701e7bd7ebb6f7ebea5c097d980039c4f904/addons/mail/static/src/components/composer_suggested_recipient/composer_suggested_recipient.js#L128-L130 we will only send the message to partnenrs, so if no partner is created we must uncheck the checkbox. opw-3168779 closes odoo/odoo#113701 X-original-commit: 24e6a16e349e1521fadc8c18574c15389c550f0c Signed-off-by: Sébastien Theys (seb) Signed-off-by: abla001 --- .../composer_suggested_recipient.js | 4 ++ .../chatter_suggested_recipient_tests.js | 43 +++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/addons/mail/static/src/components/composer_suggested_recipient/composer_suggested_recipient.js b/addons/mail/static/src/components/composer_suggested_recipient/composer_suggested_recipient.js index 3f2533a2b2e..62cb5e26def 100644 --- a/addons/mail/static/src/components/composer_suggested_recipient/composer_suggested_recipient.js +++ b/addons/mail/static/src/components/composer_suggested_recipient/composer_suggested_recipient.js @@ -87,6 +87,10 @@ export class ComposerSuggestedRecipientView extends Component { onRecordSaved: () => this._onDialogSaved(), resModel: "res.partner", title: this.composerSuggestedRecipientView.suggestedRecipientInfo.dialogText, + }, { + onClose: () => { + this._checkboxRef.el.checked = !!this.composerSuggestedRecipientView.suggestedRecipientInfo.partner; + }, }); } } diff --git a/addons/mail/static/tests/qunit_suite_tests/components/chatter_suggested_recipient_tests.js b/addons/mail/static/tests/qunit_suite_tests/components/chatter_suggested_recipient_tests.js index dd89e90f213..1407cdf6268 100644 --- a/addons/mail/static/tests/qunit_suite_tests/components/chatter_suggested_recipient_tests.js +++ b/addons/mail/static/tests/qunit_suite_tests/components/chatter_suggested_recipient_tests.js @@ -113,6 +113,49 @@ QUnit.module("mail", {}, function () { } ); + QUnit.test("suggested recipient without partner are unchecked when closing the dialog without creating partner", async function (assert) { + assert.expect(1); + const pyEnv = await startServer(); + const resFakeId1 = pyEnv['res.fake'].create({ email_cc: "john@test.be" }); + const { click, openView } = await start(); + await openView({ + res_id: resFakeId1, + res_model: 'res.fake', + views: [[false, 'form']], + }); + await click(`.o_ChatterTopbar_buttonSendMessage`); + // click on checkbox to open dialog + await document.querySelector('.o_ComposerSuggestedRecipientView:not([data-partner-id]) input[type=checkbox]').click(); + function waitForElm(selector) { + return new Promise(resolve => { + if (document.querySelector(selector)) { + return resolve(document.querySelector(selector)); + } + + const observer = new MutationObserver(mutations => { + if (document.querySelector(selector)) { + resolve(document.querySelector(selector)); + observer.disconnect(); + } + }); + + observer.observe(document.body, { + childList: true, + subtree: true + }); + }); + } + + await waitForElm('.modal-header'); + // close dialog without changing anything + document.querySelector('.modal-header > button.btn-close').click(); + + assert.notOk( + document.querySelector('.o_ComposerSuggestedRecipientView:not([data-partner-id]) input[type=checkbox]').checked, + "suggested recipient without partner must be unchecked", + ); + }); + QUnit.test( "suggested recipient with partner are checked by default", async function (assert) {