From 444bb42cf87bfb4de1fb2a1fa58f93e8dac10283 Mon Sep 17 00:00:00 2001 From: AjmalCybro Date: Tue, 23 Jan 2024 09:48:27 +0530 Subject: [PATCH] Jan 23 [UPDT] : Updated 'hide_chatter' --- hide_chatter/__manifest__.py | 2 +- hide_chatter/doc/RELEASE_NOTES.md | 7 +- .../static/src/js/form_arch_parser.js | 84 +++++++------------ 3 files changed, 36 insertions(+), 57 deletions(-) diff --git a/hide_chatter/__manifest__.py b/hide_chatter/__manifest__.py index 49b58a6f3..4ccf0374c 100644 --- a/hide_chatter/__manifest__.py +++ b/hide_chatter/__manifest__.py @@ -21,7 +21,7 @@ ############################################################################# { 'name': 'Hide Chatter', - 'version': '16.0.1.0.0', + 'version': '16.0.1.1.0', 'category': 'Discuss', 'summary': 'Disable the chatter of specific models', 'description': "Hide Chatter for any module by selecting the modules " diff --git a/hide_chatter/doc/RELEASE_NOTES.md b/hide_chatter/doc/RELEASE_NOTES.md index c23d67caf..54664af5e 100644 --- a/hide_chatter/doc/RELEASE_NOTES.md +++ b/hide_chatter/doc/RELEASE_NOTES.md @@ -3,4 +3,9 @@ #### 01.08.2023 #### Version 16.0.1.0.0 ##### ADD -- Initial Commit for Hide Chatter \ No newline at end of file +- Initial Commit for Hide Chatter + +#### 22.01.2024 +#### Version 16.0.1.1.0 +#### ADD +- Changed the entire js code \ No newline at end of file diff --git a/hide_chatter/static/src/js/form_arch_parser.js b/hide_chatter/static/src/js/form_arch_parser.js index 9411aa01e..8ccaf1f00 100644 --- a/hide_chatter/static/src/js/form_arch_parser.js +++ b/hide_chatter/static/src/js/form_arch_parser.js @@ -1,59 +1,33 @@ /** @odoo-module */ -import { - FormArchParser -} from "@web/views/form/form_arch_parser"; -import { - patch -} from "@web/core/utils/patch"; -import { - archParseBoolean -} from "@web/views/utils"; +import { patch } from "@web/core/utils/patch"; +import { useService } from "@web/core/utils/hooks"; +import { Chatter } from "@mail/components/chatter/chatter"; +import { ChatterContainer } from "@mail/components/chatter_container/chatter_container"; var rpc = require('web.rpc'); - -patch(FormArchParser.prototype, "parse", { - /** - * Patched version of the 'parse' method in 'FormArchParser'. - * Modifies the parsing behavior by removing the chatter node from the XML if the model is configured to hide the chatter. - * - * @param {string} arch - The XML architecture to parse. - * @param {Object} models - The model definitions. - * @param {string} modelName - The name of the model being parsed. - * @returns {Object} - The parsed result. - */ - parse(arch, models, modelName) { - const parsedResult = this._super.apply(this, arguments); - rpc.query({ - model: "ir.model", - method: "search", - args: [ - [ - ["model", "=", modelName] - ] - ], - kwargs: { - limit: 1 - }, - }).then((result) => { - const resModelId = result; - rpc.query({ - model: "ir.config_parameter", - method: "get_param", - args: ["chatter_enable.model_ids"], - }).then((result) => { - const modelIds = JSON.parse(result); - if (modelIds){ - if (modelIds.includes(resModelId[0])) { - const { - xmlDoc - } = parsedResult; - const chatterNode = xmlDoc.querySelector("div.oe_chatter"); - if (chatterNode && chatterNode.parentElement) { - chatterNode.parentElement.removeChild(chatterNode); - } - } - } - }) - }) - return parsedResult; +const {onMounted} = owl; +import { FormRenderer } from '@web/views/form/form_renderer'; +/** Patched FormRender for hiding the chatter. */ +patch(Chatter.prototype, "parse", { + async setup() { + this._super(...arguments) + this.orm = useService("orm"); + onMounted(async () => { + try { + // Fetch the list of model names from the configuration parameter + const response = await this.orm.call("ir.config_parameter", "get_param", [ + "chatter_enable.model_ids", ]) + const model = await rpc.query({ + model: "ir.model", + method: "search", + args: [[["model", "=", this.chatter.threadModel]]], + kwargs: { limit: 1 },}) + if ( response && response.includes(model[0]) + ) { + this.el.classList.add("d-none") + } + }catch (error) { + console.error("Error fetching configuration parameter:", error); + } + }) }, });