[FIX] mail: uncheck recipient without partner

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) <seb@odoo.com>
Signed-off-by: abla001 <abla@odoo.com>
This commit is contained in:
Abdelouahab (abla)
2023-02-26 21:11:08 +01:00
parent a8dc624635
commit 0d1a074854
2 changed files with 47 additions and 0 deletions
@@ -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;
},
});
}
}
@@ -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) {