【问题标题】:Odoo doesn't show the field label in xpathOdoo 不在 xpath 中显示字段标签
【发布时间】:2017-11-16 09:40:08
【问题描述】:

我正在向 Odoo 企业 11 中的“product.supplierinfo”模块添加一个自定义字符串字段 (stock_value),但我无法让它正确显示标签。

我继承了模块,然后向模块和通过 xpath 的视图添加了一个新字段。

问题:与新字段相关的字符串未显示。

模块:

class class_name(models.Model):
    _inherit                        = 'product.supplierinfo'
    stock_value                     = fields.Integer(string="Stock")

查看:

<!-- Stock value in the vendors -->
<record id="view_product_product_supplierinfo_form_view" model="ir.ui.view">
    <field name="name">product.supplierinfo.product.form</field>
    <field name="model">product.supplierinfo</field>
    <field name="inherit_id" ref="product.product_supplierinfo_form_view"/>
    <field name="arch" type="xml">
    <xpath expr="//field[@name='price']" position="after">
        <field name="stock_value" />
    </xpath>
    </field>
</record>

结果:如您所见,价格值下方有一个零,但未显示字符串标签“Stock”。

尝试了其他方法:

添加下一个代码:

<separator />
<label for="stock_value" string="Stock Value"/>

给我

把字段放在一个组里给我

我还尝试在最后一个视图中将位置更改为“之前”,但我无法使其看起来像应有的那样。我尝试使用@string,但它不再有效。

感谢您的帮助。

【问题讨论】:

    标签: python xml odoo odoo-11


    【解决方案1】:

    问题在于price 字段位于div 容器内,因此您必须将字段放在div 之后(这是DOM 中price 字段的父级)。因此,您必须告诉xpath,您要将字段放在字段price 的DOM 父级之后,而不是像代码中那样放在字段之后。根据您要查找的样式,您可以选择以下任一选项:

    选项 1(您也可以将 class="oe_inline 添加到您的字段中):

    <!-- Stock value in the vendors -->
    <record id="view_product_product_supplierinfo_form_view" model="ir.ui.view">
        <field name="name">product.supplierinfo.product.form</field>
        <field name="model">product.supplierinfo</field>
        <field name="inherit_id" ref="product.product_supplierinfo_form_view"/>
        <field name="arch" type="xml">
            <xpath expr="//field[@name='price']/.." position="after">
                <label for="stock_value"/>
                <div>
                    <field name="stock_value"/>
                </div>
            </xpath>
        </field>
    </record>
    

    选项 2

    <!-- Stock value in the vendors -->
    <record id="view_product_product_supplierinfo_form_view" model="ir.ui.view">
        <field name="name">product.supplierinfo.product.form</field>
        <field name="model">product.supplierinfo</field>
        <field name="inherit_id" ref="product.product_supplierinfo_form_view"/>
        <field name="arch" type="xml">
            <xpath expr="//field[@name='price']/.." position="after">
                <field name="stock_value"/>
            </xpath>
        </field>
    </record>
    

    【讨论】:

    • 我认为您添加了两次相同的代码。 :D 无论哪种方式都有效。我不知道我能做到这一点。非常感谢。
    • 我做了 :D 我更新了答案以更正,以防万一您更喜欢第二个选项的样式。不客气!
    猜你喜欢
    • 1970-01-01
    • 2015-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-09
    • 1970-01-01
    相关资源
    最近更新 更多