From 9c8a987e0f49aace4c040bb86b5784066900b6da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20K=C3=BChn?= Date: Wed, 19 Oct 2022 13:01:46 +0000 Subject: [PATCH] [FIX] mail: no write on read-only SuggestedRecipientInfo/isSelected MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this commit, when a recipient is suggested in composer header and current user click on checkbox, there was the following warning in the console: ``` read-only SuggestedRecipientInfo/isSelected on record(SuggestedRecipientInfo_1) was updated ``` The state of a selected suggested recipient is determined by being manually selected on UI, but also that there's a partner related to this recipient. `isSelected` is a computed field with itself as dependency, and it was also imperatively set. We don't want any computed field to be set imperatively, hence the warning in the console. This commit fixes the issue by introducing another field that is specific to selection on UI by current user. This field does not depend on whether there's a partner. This field is imperatively set, and then `isSelected` is fully declarative as a computed field with no self dependency and no imperative update. Task-3032869 closes odoo/odoo#103573 X-original-commit: 8e2980e1e871a8046f09d3d0affb6400ee030eeb Signed-off-by: Louis Wicket (wil) Signed-off-by: Alexandre Kühn (aku) --- .../composer_suggested_recipient.js | 2 +- addons/mail/static/src/models/suggested_recipient_info.js | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) 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 f981af8ea64..120b55aed57 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 @@ -62,7 +62,7 @@ export class ComposerSuggestedRecipient extends Component { return; } const isChecked = this._checkboxRef.el.checked; - this.composerSuggestedRecipientView.suggestedRecipientInfo.update({ isSelected: isChecked }); + this.composerSuggestedRecipientView.suggestedRecipientInfo.update({ isChecked }); if (!this.composerSuggestedRecipientView.suggestedRecipientInfo.partner) { // Recipients must always be partners. On selecting a suggested // recipient that does not have a partner, the partner creation form diff --git a/addons/mail/static/src/models/suggested_recipient_info.js b/addons/mail/static/src/models/suggested_recipient_info.js index 0c302897915..8c8ae962eb6 100644 --- a/addons/mail/static/src/models/suggested_recipient_info.js +++ b/addons/mail/static/src/models/suggested_recipient_info.js @@ -32,6 +32,12 @@ registerModel({ id: attr({ identifying: true, }), + /** + * Determines whether this suggested recipient has been checked on UI. + * A suggested recipient info is checked when current user manually set + * checkbox to "checked" value. + */ + isChecked: attr(), /** * Determines whether `this` will be added to recipients when posting a * new message on `this.thread`. @@ -41,7 +47,7 @@ registerModel({ * Prevents selecting a recipient that does not have a partner. */ compute() { - return this.partner ? this.isSelected : false; + return this.partner ? this.isChecked : false; }, default: true, }),