[FIX] mail: add recipients as follower when sending message
Part-of: odoo/odoo#117681
This commit is contained in:
@@ -681,6 +681,7 @@ export class ThreadService {
|
||||
const tmpId = lastMessageId + 0.01;
|
||||
const params = {
|
||||
context: {
|
||||
mail_post_autofollow: !isNote && thread.hasWriteAccess,
|
||||
temporary_id: tmpId,
|
||||
},
|
||||
post_data: {
|
||||
|
||||
@@ -206,6 +206,26 @@ QUnit.test(
|
||||
}
|
||||
);
|
||||
|
||||
QUnit.test(
|
||||
"suggested recipients should be added as follower when posting a message",
|
||||
async (assert) => {
|
||||
const pyEnv = await startServer();
|
||||
const partnerId = pyEnv["res.partner"].create({
|
||||
display_name: "John Jane",
|
||||
email: "john@jane.be",
|
||||
});
|
||||
const fakeId = pyEnv["res.fake"].create({ partner_ids: [partnerId] });
|
||||
const { openFormView } = await start({
|
||||
serverData: { views },
|
||||
});
|
||||
await openFormView("res.fake", fakeId);
|
||||
await click("button:contains(Send message)");
|
||||
await insertText(".o-mail-Composer-input", "Dummy Message");
|
||||
await click(".o-mail-Composer-send");
|
||||
assert.strictEqual($(".o-mail-Followers-counter").text(), "1");
|
||||
}
|
||||
);
|
||||
|
||||
QUnit.test(
|
||||
"suggested recipient without partner are unchecked when closing the dialog without creating partner",
|
||||
async (assert) => {
|
||||
|
||||
@@ -448,7 +448,7 @@ patch(MockServer.prototype, "mail/controllers/discuss", {
|
||||
res["hasReadAccess"] = false;
|
||||
return res;
|
||||
}
|
||||
res['canPostOnReadonly'] = thread_model === 'mail.channel'; // model that have attr _mail_post_access='read'
|
||||
res["canPostOnReadonly"] = thread_model === "mail.channel"; // model that have attr _mail_post_access='read'
|
||||
if (request_list.includes("activities")) {
|
||||
const activities = this.pyEnv["mail.activity"].searchRead([
|
||||
["id", "in", thread.activity_ids || []],
|
||||
|
||||
@@ -154,6 +154,9 @@ patch(MockServer.prototype, "mail/models/mail_thread", {
|
||||
*/
|
||||
_mockMailThreadMessagePost(model, ids, kwargs, context) {
|
||||
const id = ids[0]; // ensure_one
|
||||
if (context?.["mail_post_autofollow"] && kwargs["partner_ids"].length > 0) {
|
||||
this._mockMailThreadMessageSubscribe(model, ids, kwargs["partner_ids"]);
|
||||
}
|
||||
if (kwargs.attachment_ids) {
|
||||
const attachments = this.getRecords("ir.attachment", [
|
||||
["id", "in", kwargs.attachment_ids],
|
||||
@@ -197,7 +200,7 @@ patch(MockServer.prototype, "mail/models/mail_thread", {
|
||||
* @param {string} model not in server method but necessary for thread mock
|
||||
* @param {integer[]} ids
|
||||
* @param {integer[]} partner_ids
|
||||
* @param {integer[]} subtype_ids
|
||||
* @param {integer[]} [subtype_ids]
|
||||
* @returns {boolean}
|
||||
*/
|
||||
_mockMailThreadMessageSubscribe(model, ids, partner_ids, subtype_ids) {
|
||||
@@ -207,6 +210,14 @@ patch(MockServer.prototype, "mail/models/mail_thread", {
|
||||
["partner_id", "=", partner_id],
|
||||
])[0];
|
||||
if (!followerId) {
|
||||
if (!subtype_ids || subtype_ids.length === 0) {
|
||||
subtype_ids = this.pyEnv["mail.message.subtype"].search([
|
||||
["default", "=", true],
|
||||
"|",
|
||||
["res_model", "=", model],
|
||||
["res_model", "=", false],
|
||||
]);
|
||||
}
|
||||
followerId = this.pyEnv["mail.followers"].create({
|
||||
is_active: true,
|
||||
partner_id,
|
||||
@@ -215,6 +226,9 @@ patch(MockServer.prototype, "mail/models/mail_thread", {
|
||||
subtype_ids: subtype_ids,
|
||||
});
|
||||
}
|
||||
this.pyEnv[model].write(ids, {
|
||||
message_follower_ids: [followerId],
|
||||
});
|
||||
this.pyEnv["res.partner"].write([partner_id], {
|
||||
message_follower_ids: [followerId],
|
||||
});
|
||||
|
||||
@@ -95,6 +95,7 @@ insertModelFields("mail.message", {
|
||||
res_model_name: { string: "Res Model Name", type: "char" },
|
||||
});
|
||||
insertModelFields("mail.message.subtype", {
|
||||
default: { default: true },
|
||||
subtype_xmlid: { type: "char" },
|
||||
});
|
||||
insertModelFields("mail.tracking.value", {
|
||||
|
||||
Reference in New Issue
Block a user