diff --git a/addons/mail/static/src/views/activity/activity_arch_parser.js b/addons/mail/static/src/views/activity/activity_arch_parser.js index e9a3e0f9205..24ecf16734f 100644 --- a/addons/mail/static/src/views/activity/activity_arch_parser.js +++ b/addons/mail/static/src/views/activity/activity_arch_parser.js @@ -46,8 +46,12 @@ export class ActivityArchParser extends XMLParser { // Keep track of last update so images can be reloaded when they may have changed. if (node.tagName === "img") { const attSrc = node.getAttribute("t-att-src"); - if (attSrc && /\bactivity_image\b/.test(attSrc) && !fieldNodes.write_date) { - fieldNodes.write_date = { type: "datetime" }; + if ( + attSrc && + /\bactivity_image\b/.test(attSrc) && + !Object.values(fieldNodes).some((f) => f.name === "write_date") + ) { + fieldNodes.write_date_0 = { name: "write_date", type: "datetime" }; } } diff --git a/addons/test_mail/static/tests/activity_tests.js b/addons/test_mail/static/tests/activity_tests.js index cdac9b367c6..05392c68139 100644 --- a/addons/test_mail/static/tests/activity_tests.js +++ b/addons/test_mail/static/tests/activity_tests.js @@ -880,4 +880,50 @@ QUnit.module("test_mail", {}, function () { }); assert.containsN(document.body, ".luxon", 2); }); + + QUnit.test("test displaying image (write_date field)", async (assert) => { + // the presence of write_date field ensures that the image is reloaded when necessary + assert.expect(2); + + Object.assign(serverData.views, { + "mail.test.activity,false,activity": ` + + +
+ + +
+
+
`, + }); + + const { target, openView } = await start({ + serverData, + mockRPC(route, { method, kwargs }, result) { + if (method === "web_search_read") { + assert.deepEqual(kwargs.fields, ["write_date", "id"]); + return Promise.resolve({ + length: 2, + records: [ + { id: 1, write_date: "2022-08-05 08:37:00" }, + { id: 2, write_date: "2022-08-05 08:37:00" }, + ], + }); + } + }, + }); + await openView({ + res_model: "mail.test.activity", + views: [[false, "activity"]], + }); + + assert.ok( + target + .querySelector(".o_activity_record img") + .dataset.src.endsWith( + "/web/image?model=partner&field=image&id=2&unique=1659688620000" + ), + "image src is the preview image given in option" + ); + }); });