You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Odoo17浏览器标签页标题修改问题:升级后代码无效

Odoo17移除浏览器标签页“Odoo”前缀失败问题排查

我将模块从Odoo15升级至Odoo17后,发现浏览器标签页始终显示带“Odoo”前缀的标题(如打开销售模块时显示“Odoo-Quotation”),希望移除该前缀。编写了如下代码后运行无报错,但“Odoo”标题仍未消失,请问原因是什么?

浏览器标签页显示Odoo前缀

原代码

/** @odoo-module */
import { WebClient } from "@web/webclient/webclient";
import { patch } from "@web/core/utils/patch";
import { session } from "@web/session";
import { useService } from "@web/core/utils/hooks";

patch(WebClient.prototype, {
    "legion_hide_odoo_tab.WebClient": {
        setup() {
            this._super.apply(this, arguments);
            this.rpc = useService("rpc");
            var domain = session.user_companies.allowed_companies;
            this.title.setParts({ zopenerp: "" });
            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';
                const app_system_name = session.app_system_name || '';
                obj.title.setParts({ zopenerp: result });
            });
        }
    }
});

问题原因及修复方案

1. Patch语法错误

Odoo17的patch函数用法与Odoo15不同,你当前的嵌套命名空间写法不符合新规范,正确方式是直接将补丁标识作为第二个参数传入,而非嵌套对象。

2. RPC调用上下文错误

你在调用rpc.query时,误用了未定义的全局rpc变量,而非通过useService获取的this.rpc,导致RPC调用静默失败,后续的标题更新逻辑根本没有执行。

3. 标题键名变更

Odoo17中控制标签页前缀的标题键已从zopenerp改为default,原代码中设置zopenerp为空不会对当前标题产生影响。

修复后的代码

/** @odoo-module */
import { WebClient } from "@web/webclient/webclient";
import { patch } from "@web/core/utils/patch";
import { session } from "@web/session";
import { useService } from "@web/core/utils/hooks";

patch(WebClient.prototype, 'legion_hide_odoo_tab.WebClient', {
    setup() {
        this._super(...arguments);
        this.rpc = useService("rpc");
        const domain = session.user_companies.allowed_companies;
        
        // 先清空前缀
        this.title.setParts({ default: "" });
        
        this.rpc.query({
            fields: ['name', 'id'],
            model: 'res.config.settings',
            method: 'current_company_id',
            args: [domain, domain],
        }).then((result) => {
            const app_system_name = session.app_system_name || '';
            // 用公司名称替换前缀,或直接设为空
            this.title.setParts({ default: result || app_system_name });
        }).catch(() => {
            // RPC调用失败时确保前缀被清空
            this.title.setParts({ default: "" });
        });
    }
});

简化方案(无需RPC)

如果仅需移除“Odoo”前缀,无需动态获取公司名称,可直接简化代码:

/** @odoo-module */
import { WebClient } from "@web/webclient/webclient";
import { patch } from "@web/core/utils/patch";

patch(WebClient.prototype, 'legion_hide_odoo_tab.WebClient', {
    setup() {
        this._super(...arguments);
        // 直接清空默认前缀
        this.title.setParts({ default: "" });
        // 监听路由变化,确保页面切换时标题不会重新带上前缀
        this.bus.addEventListener('ROUTE_CHANGE', () => {
            this.title.setParts({ default: "" });
        });
    }
});

无代码解决方案

还可通过系统参数全局修改:进入「设置」→「技术」→「系统参数」,添加或修改web.base.url.title参数,将值设为空或自定义标题,无需编写代码即可生效。


内容的提问来源于stack exchange,提问作者Muhammad Tariq

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.02 20:43:17