This question has been flagged
2 Replies
4569 Views

hello, I want to change the Odoo browser tab title, by extending js webclient, but I always fail.

Here's what I wrote on the js and nothing happend:


/** @odoo-module **/

import { ActionContainer } from "@web/webclient/actions/action_container";
import { NavBar } from "@web/webclient/navbar/navbar";
import { useBus, useEffect, useService } from "@web/core/utils/hooks";
import { useTooltip } from "@web/core/tooltip/tooltip_hook";
import { NotUpdatable } from "@web/core/utils/components";
import { MainComponentsContainer } from "@web/core/main_components_container";
import { useOwnDebugContext } from "@web/core/debug/debug_context";
import { registry } from "@web/core/registry";
import { DebugMenu } from "@web/core/debug/debug_menu";
import { localization } from "@web/core/l10n/localization";

import { WebClient } from "@web/webclient/webclient";
import { hasTouch } from "@web/core/browser/feature_detection";

const { hooks } = owls;

export class WebClientExtends extends WebClient {
setup() {
this.menuService = useService("menu");
this. actionService = useService("action");
this. title = useService("title");
this. router = useService("router");
this. user = useService("user");
useService("legacy_service_provider");
useOwnDebugContext({ categories: ["default"] });
if (this. env. debug) {
registry. category("systray").add(
"web. debug_mode_menu",
;{
Components: DebugMenu,
},
{ sequences: 100 }
);
}
this. localization = localization;
// this. title. setParts({ zopenerp: "Odoo" }); // zopenerp is easy to grep
this. title. setParts({ zopenerp: "Cookies" }); // zopenerp is easy to grep
useBus(this.env.bus, "ROUTE_CHANGE", this.loadRouterState);
useBus(this.env.bus, "ACTION_MANAGER:UI-UPDATED", (mode) => {
if (mode !== "new") {
this.el.classList.toggle("o_fullscreen", mode === "fullscreen");
}
});
useEffect(
() => {
this. loadRouterState();
},
() => []
);
useExternalListener(window, "click", this. onGlobalClick, { capture: true });
useTooltip();
}
 
}
WebClientExtends. components = { ...WebClient. components};

Can anyone help me fix this code?

Avatar
Discard
Best Answer

Hi Elsanita Sinaga

Try this

/** @odoo-module **/

import { WebClient } from "@web/webclient/webclient";
import { patch } from "@web/core/utils/patch";
import { session } from "@web/session";

patch(WebClient.prototype, "Your custom module.WebClient", {
setup() {
this._super.apply(this, arguments);
const app_system_name = 'Tab Title';
this.title.setParts({ zopenerp: app_system_name }); // zopenerp is easy to grep
}
});

You can find sample code here:https://apps.odoo.com/apps/modules/15.0/app_odoo_customize

Avatar
Discard
Best Answer

Hi,

Try Like below

/** @odoo-module **/

import { WebClient } from "@web/webclient/webclient";
import { patch } from "@web/core/utils/patch";
import { session } from "@web/session";
import rpc from 'web.rpc';


patch(WebClient.prototype, "module_name.WebClient", {
setup() {
this._super.apply(this, arguments);
var domain = session.user_companies.allowed_companies;
this.title.setParts({ zopenerp: "New title" }); // zopenerp is easy to grep
var obj = this;
var def = rpc.query({
fields: ['name','id',],
model: 'res.config.settings',
method: 'current_company_id',
args: [domain, domain],
})
.then(function (result) {
const app_system_name = session.app_system_name || 'New title';
obj.title.setParts({ zopenerp: result }); // zopenerp is easy to grep
});
}
});

Regards

Avatar
Discard