How can I disable the attachments tab in oe_chatter?
I tried with this code but it doesn't work:
<div class="oe_chatter">
<field name="message_ids" widget="mail_thread" options="{'disable_attachment_box': True}"/>
</div>
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
How can I disable the attachments tab in oe_chatter?
I tried with this code but it doesn't work:
<div class="oe_chatter">
<field name="message_ids" widget="mail_thread" options="{'disable_attachment_box': True}"/>
</div>
It will be a pleasure to know, We are introducing the document upload from chatter to disable shortly. You specify disabled_upload = True https://github.com/odoo/odoo/pull/44568/commits/0bd340e15e4cac5f4c990bbdda54c4fcefdc66da
You can achieve that by simply extending the message log template for attachments. If I need to disable add_attachments + button in message logs attachments section I can do the following steps:
Create an xml file under static > src > xml > attachment_log_extend.xml
Append the file in the manifest: 'qweb': ['static/src/xml/attachment_log_extend.xml']
Extend the div
<t t-extend="mail.chatter.AttachmentBox">
<t t-jquery=".o_upload_attachments_button" t-operation="replace">
<t t-if="widget.currentResModel == 'my_custom.model'">
<span class="btn btn-link o_upload_attachments_button">
</span>
</t>
<t t-else="not widget.currentResModel == 'next-condition'">
<span class="btn btn-link o_upload_attachments_button"><span class="fa fa-plus-square"/> Add Attachments</span>
</t>
</t>
</t>
From checking the code it appears that Odoo has not fully implemented this feature. The code responsible for rendering the chatter section does not check for the attribute in setting the options so the disable_attachment_box option is always False.
To correct you need to create override the _renderNode method of the FormRenderer class of addons/mail/static/src/js/form_renderer.js in a custom module for example like so:
odoo.define('my_module.form_renderer', function (require) {
"use strict";
var Chatter = require('mail.Chatter');
var FormRenderer = require('web.FormRenderer');
FormRenderer.include({
_renderNode: function (node) {
if (node.tag === 'div' && node.attrs.class === 'oe_chatter') {
if (!this.chatter) {
this.chatter = new Chatter(this, this.state, this.mailFields, {
isEditable: this.activeActions.edit,
viewType: 'form',
disable_attachment_box: 'disable_attachment_box' in node.attrs,
});
this.chatter.appendTo($('<div>'));
this._handleAttributes(this.chatter.$el, node);
} else {
this.chatter.update(this.state);
}
return this.chatter.$el;
} else {
return this._super.apply(this, arguments);
}
},
});
});
This adds the line in bold face.
Load the javascript file (here called fix_disable_attachments.js) with an xml file:
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="assets_backend" name="my_module assets" inherit_id="web.assets_backend">
<xpath expr="script[last()]" position="after">
<script type="text/javascript" src="/my_module/static/src/js/fix_disable_attachments.js"/>
</xpath>
</template>
</odoo>
And make sure the xml file is loaded in the __manifest__.py file of my_module.
The attribute 'disable_attachment_box' should then be set on the div having the class oe_chatter instead of the on the field message_ids like so (in case you want to change an existing view):
<xpath expr="//div[@class='oe_chatter']" position="attributes">
<attribute name="disable_attachment_box">1</attribute>
</xpath>
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign up