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

Odoo 12树视图中如何隐藏percentpie组件旁的字段string文本

解决方案

你之前尝试的show_string参数仅在部分第三方percentpie组件中支持,Odoo原生的percentpie组件未实现该参数,因此无法生效。以下是两种经过验证的可行方案:

方法1:自定义CSS实现(兼容性最好,支持所有Odoo版本)

该方案不需要修改组件源码,仅通过样式控制即可同时实现标签隐藏、饼图居中的需求,且不会影响其他页面的percentpie组件使用。
修改后的视图代码如下:

<record model="ir.ui.view" id="field_partida_fertilizer_tree">
    <field name="name">field.diary.partida.fertilizer.tree.view</field>
    <field name="model">field.diary.partida.fertilizer</field>
    <field name="priority" eval="17"/>
    <field name="arch" type="xml">
        <!-- 内嵌自定义CSS,仅作用于当前视图 -->
        <style>
            /* 隐藏percentpie内部的文本标签 */
            .hide_pie_label .o_percentpie_text {
                display: none !important;
            }
            /* 让饼图在单元格内居中 */
            .hide_pie_label .o_list_cell_content {
                display: flex !important;
                justify-content: center !important;
            }
        </style>
        <tree string="Fertilizante">
            <field string='Nombre' name="fertilizer"/>
            <!-- 给需要隐藏标签的字段添加自定义类 -->
            <field string='N' name="nitrato" class="hide_pie_label" widget="percentpie"/>
            <field string='P' name="fosforo" class="hide_pie_label" widget="percentpie"/>
            <field string='K' name="potasio" class="hide_pie_label" widget="percentpie"/>
            <field string='Cantidad (kg)' name="quantity"/>
        </tree>
    </field>
</record>

如果上述CSS未生效,可通过浏览器F12开发者工具选中饼图的文本元素,替换对应类名即可。

方法2:添加空label属性(部分版本适用)

如果你的Odoo版本原生支持字段的label属性优先级高于列头string,可以直接给对应字段加label=""属性:

<field string='N' name="nitrato" label="" widget="percentpie"/>

该方案操作最简单,但部分Odoo版本会同时清空列头的显示文本,使用前需要先测试适配性。

不推荐使用之前将文本设为白色的方案,该方案在选中行、深色模式下会出现文本显露的问题,也不符合无障碍访问要求。

内容的提问来源于stack exchange,提问作者Wylliam M

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.02 05:24:05