[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 <luvi@odoo.com>
This commit is contained in:
@@ -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" };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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": `
|
||||
<activity string="MailTestActivity">
|
||||
<templates>
|
||||
<div t-name="activity-box">
|
||||
<img t-att-src="activity_image('partner', 'image', record.id.raw_value)"/>
|
||||
<field name="id"/>
|
||||
</div>
|
||||
</templates>
|
||||
</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"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user