Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
2 Răspunsuri
1215 Vizualizări

In odoo 15 I used to do this via js via editing this:

isAttachmentBoxVisibleInitially: (
this._getFieldOption('message_ids', 'open_attachments', true) ||
this._getFieldOption('message_follower_ids', 'open_attachments', false)
),

But in odoo 17 this makes no sense. I found this in chatter.js

static defaultProps = {
compactHeight: false,
hasActivities: true,
hasFollowers: true,
hasMessageList: true,
isChatterAside: false,
hasParentReloadOnAttachmentsChanged: false,
hasParentReloadOnFollowersUpdate: false,
hasParentReloadOnMessagePosted: false,
isAttachmentBoxVisibleInitially: false,
isInFormSheetBg: true,
threadId: false,
};

But so far I've been unable to make it work, everytime i try changing the inherited js i get either a blank page with an error (bottom-left) "An error ocurred while loading javascript modules, you may find more information in the devtools console", or odoo loads as usual and the same error appears. And there is no info on the error apart from the js not loading (checked via logs and via f12 in the browser).

Has anyone this or anything similar?

Imagine profil
Abandonează
Cel mai bun răspuns

Hi Apiuser,

Would you like to test snippet from me? I tried to replace the default compileChatter function and it works. Maybe you can try with other inheritance that you can do, but this also works. Might not be the best solution, but hopefully it helps.

/* @odoo-module */

import { registry } from "@web/core/registry";

import { evaluateExpr } from "@web/core/py_js/py";

import { append, createElement, setAttributes } from "@web/core/utils/xml";


// rewrite the default compileChatter function to set isAttachmentBoxVisibleInitially to true

function compileChatterOpenAttachments(node, params) {

let hasActivities = false;

let hasFollowers = false;

let hasMessageList = false;

let hasParentReloadOnAttachmentsChanged;

let hasParentReloadOnFollowersUpdate = false;

let hasParentReloadOnMessagePosted = false;

let isAttachmentBoxVisibleInitially = true; // here we change the initial value

for (const childNode of node.children) {

const options = evaluateExpr(childNode.getAttribute("options") || "{}");

switch (childNode.getAttribute("name")) {

case "activity_ids":

hasActivities = true;

break;

case "message_follower_ids":

hasFollowers = true;

hasParentReloadOnFollowersUpdate = Boolean(options["post_refresh"]);

isAttachmentBoxVisibleInitially =

isAttachmentBoxVisibleInitially || Boolean(options["open_attachments"]);

break;

case "message_ids":

hasMessageList = true;

hasParentReloadOnAttachmentsChanged = options["post_refresh"] === "always";

hasParentReloadOnMessagePosted = Boolean(options["post_refresh"]);

isAttachmentBoxVisibleInitially =

isAttachmentBoxVisibleInitially || Boolean(options["open_attachments"]);

break;

}

}

const chatterContainerXml = createElement("t");

setAttributes(chatterContainerXml, {

"t-component": "__comp__.mailComponents.Chatter",

hasActivities,

hasFollowers,

hasMessageList,

hasParentReloadOnAttachmentsChanged,

hasParentReloadOnFollowersUpdate,

hasParentReloadOnMessagePosted,

isAttachmentBoxVisibleInitially,

threadId: "__comp__.props.record.resId or undefined",

threadModel: "__comp__.props.record.resModel",

webRecord: "__comp__.props.record",

saveRecord: "() => __comp__.save and __comp__.save()",

});

const chatterContainerHookXml = createElement("div");

chatterContainerHookXml.classList.add("o-mail-ChatterContainer", "o-mail-Form-chatter");

append(chatterContainerHookXml, chatterContainerXml);

return chatterContainerHookXml;

}


// remove the default chatter_compiler from the registry and add the new one

registry.category("form_compilers").remove("chatter_compiler",)

registry.category("form_compilers").add("chatter_compiler", {

selector: "div.oe_chatter",

fn: compileChatterOpenAttachments,

});

Imagine profil
Abandonează
Autor

This solution does work but didn't want to overwrite all the file. But you are right I was looking in the wrong place, I was looking in the chatter.js and needed to check form_compiler.js and overwrite function compileChatter.

Autor Cel mai bun răspuns

For anyone wondering, I finally solved it like so:

patch(FormCompiler.prototype, {
compile(node, params) {
const res = super.compile(node, params);
const chatterContainerXml = res.querySelector("t[t-component='__comp__.mailComponents.Chatter']");
if (chatterContainerXml) {
chatterContainerXml.setAttribute("isAttachmentBoxVisibleInitially", "true");
}
return res;
},
});
Imagine profil
Abandonează

Great that it give you a little bit of insights for your challenge.
If you don't mind, you could give an upvote to my answer or mark it as solve I guess.

Good Luck

Autor

Well, I wanted to mark my answer as solved, as it is what I was looking for, but apparently i can't. I upvotted yours.

sure, thanks!

Related Posts Răspunsuri Vizualizări Activitate
2
iul. 25
1616
1
mar. 25
1174
1
dec. 24
1068
1
dec. 24
1430
2
aug. 24
2852