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

Odoo17客户门户添加按钮失败求助:视图已配置但按钮不显示

Odoo客户门户添加按钮不显示问题排查

问题场景

想在客户门户中添加一个按钮,预期效果参考截图:
客户门户截图

编写了如下继承视图代码:

<template id="portal_my_home" name="Show Blogposts" customize_show="True" inherit_id="portal.portal_my_home" priority="20">

    <xpath expr="//div[hasclass('o_portal_docs')]" position="before">
        <t t-set="portal_client_category_enable" t-value="True"/>
    </xpath>

    <div id="portal_client_category" position="inside">
        <t t-call="portal.portal_docs_entry">
            <t t-set="title">Test</t>
            <t t-set="url" t-value="'/my/controller'"/>
            <t t-set="text">Test Button</t>
        </t>
    </div>

</template>

已完成的操作:

  • 将视图添加到模块manifest的data部分
  • 重新安装模块
  • 在开发者模式「技术>视图」中能看到该视图,且portal.portal_my_home已正确继承自定义视图
  • 尝试过多种写法变体,参考过HR模块相关实现,但按钮始终无法显示

问题排查与解决方案

1. 核心问题:目标节点不存在

你的代码中使用<div id="portal_client_category" position="inside">,但原视图portal.portal_my_home中默认没有id="portal_client_category"的节点,导致插入的内容没有挂载点。你设置了portal_client_category_enable变量,但没有对应的容器去渲染内容。

2. 正确写法示例

方法一:直接插入到现有文档区域

直接在默认的文档容器内添加新入口,无需额外定义变量:

<template id="portal_my_home" name="Add Test Button" customize_show="True" inherit_id="portal.portal_my_home" priority="20">
    <!-- 在现有文档区域内插入新按钮 -->
    <xpath expr="//div[hasclass('o_portal_docs')]" position="inside">
        <t t-call="portal.portal_docs_entry">
            <t t-set="title">Test</t>
            <t t-set="url" t-value="'/my/controller'"/>
            <t t-set="text">Test Button</t>
        </t>
    </xpath>
</template>

方法二:创建独立分类区域

如果需要单独的分类块,需先定义容器并配合启用变量:

<template id="portal_my_home" name="Add Test Button" customize_show="True" inherit_id="portal.portal_my_home" priority="20">
    <!-- 设置启用变量并创建分类容器 -->
    <xpath expr="//div[hasclass('o_portal_docs')]" position="before">
        <t t-set="portal_test_category_enable" t-value="True"/>
        <div t-if="portal_test_category_enable" class="o_portal_docs">
            <h2 class="h5 mb-4">测试分类</h2>
            <div class="row o_portal_docs_entries" id="portal_test_category">
            </div>
        </div>
    </xpath>

    <!-- 在自定义容器内添加按钮 -->
    <xpath expr="//div[@id='portal_test_category']" position="inside">
        <t t-call="portal.portal_docs_entry">
            <t t-set="title">Test</t>
            <t t-set="url" t-value="'/my/controller'"/>
            <t t-set="text">Test Button</t>
        </t>
    </xpath>
</template>

3. 额外检查点

  • 权限控制:确保门户用户有权访问/my/controller路由,控制器中需指定auth='user'或auth='public'(根据业务需求)
  • 清除缓存:重新安装模块后,手动清除浏览器缓存和Odoo服务器缓存(开发者模式下点击「清除缓存」按钮)
  • 优先级设置:若有其他模块继承portal.portal_my_home,将你的视图priority设为更高值(比如30),确保修改优先生效

内容的提问来源于stack exchange,提问作者unnamed-dev

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.18 00:13:16