From 38acd9f7d490fcd8ab7e8244ae93e907a01f528a Mon Sep 17 00:00:00 2001 From: Jorge Pinna Puissant Date: Wed, 12 Apr 2023 11:29:38 +0000 Subject: [PATCH] [FIX] mail, test_mail: Keep track of last update images Since [1], a unique id is used for fieldNodes, therefore, the code to keep track of last update images on the activity view needs to change also. Before this commit, we search the write_date on the fieldModes using the id, and if it's not present, a new one is created using as id "write_date". Now, as a unique id is needed, we search using the name, and if it's not present, a new one is created using as id "write_date_0". Note that this is already the behavior on kanbanParse. [1]: https://github.com/odoo/odoo/commit/baebb6a5b05ac8d59501a6071a5513e31a4ca047 closes odoo/odoo#118320 Signed-off-by: Luca Vitali --- .../views/activity/activity_arch_parser.js | 8 +++- .../test_mail/static/tests/activity_tests.js | 46 +++++++++++++++++++ 2 files changed, 52 insertions(+), 2 deletions(-) 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" + ); + }); });