【问题标题】:Hide string name from field in odoo 12从odoo 12中的字段隐藏字符串名称
【发布时间】:2021-09-27 11:05:03
【问题描述】:

当您在 odoo 中定义一个字段时,默认情况下,它会显示该值的字符串,并在其旁边显示该值。

如果不将字段放在组标签之间,则字符串值不会出现。

问题是我正在定义一个不包含组标签的树视图:

<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">

        <tree string="Fertilizante">
            <field string= 'Nombre' name="fertilizer"/>
            <field string='N' name="nitrato" options='{"show_string": False}' widget="percentpie"/>
            <field string='P' name="fosforo" options='{"fg_color": "white"}' widget="percentpie"/>
            <field string='K' name="potasio" options='{"fg_color": "white"}' widget="percentpie"/>
            <field string='Cantidad (kg)' name="quantity"/>
        </tree>
    </field>
</record>

通过使用小部件百分比,我可以显示:

我想隐藏图表旁边的字母 N,而不是列,我找不到小部件的任何属性来做到这一点。我可以解决这个问题的唯一方法是为文本赋予白色,使其与背景一起消失,但列不能居中。

我已尝试使用我在 GitHub 上找到的选项 show_string,但它不起作用。

任何帮助都会很棒... 谢谢!

【问题讨论】:

  • 为什么不用string=""?
  • 因为这将使用默认的字符串名称或 odoo 中的字段模型。它总是显示一些东西,即使它是空的。

标签: widget odoo odoo-12


【解决方案1】:

Odoo 在PercentPie 模板中定义了一个条件来显示字符串属性值:

<span t-if="widget.string"><t t-esc="widget.string"/></span>

您可以更改模板并根据通过 options 属性传递的值 (show_string) 定义新条件:

<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">

    <t t-extend="FieldPercentPie">
        <t t-jquery="span" t-operation="attributes">
            <attribute name="t-if">widget.string and (widget.attrs.options.show_string === undefined or widget.attrs.options.show_string)</attribute>
        </t>
    </t>

</templates>

使用上述内容创建一个新的 XML 文件,并将其添加到清单文件的 qweb 部分下。

示例:

<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">
    <tree string="Fertilizante">
        <field string='Nombre' name="fertilizer"/>
        <field name="nitrato" options='{"show_string": False}' widget="percentpie"/>
        <field name="fosforo" options='{"show_string": False}' widget="percentpie"/>
        <field name="potasio" options='{"show_string": False}' widget="percentpie"/>
        <field string='Cantidad (kg)' name="quantity"/>
    </tree>
</field>

【讨论】:

    猜你喜欢
    • 2020-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-21
    • 2013-01-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多