Odoo,为选股添加新领域

时间:2017-10-19 03:45:38

标签: python openerp

我试图在模型move_lines中的stock.picking中添加新字段,当然,我继承了模型stock.picking。是这样尝试:

<xpath expr="//form/notebook/page/field[@name='move_lines']/form/field[@name='state']" position="after">
    <field name="add_new_field"/>
</xpath>

但我总是得到错误:

Element '<xpath expr="//form/notebook/page/field[@name='move_lines']/form/field[@name='state']">' cannot be located in parent view

2 个答案:

答案 0 :(得分:0)

您收到错误,因为它无法找到路径。

只需将下面的代码作为xpath就可以了:

<xpath="//field[@name='move_lines']/form//field[@name='state']" position="after">

答案 1 :(得分:0)

move_lines的定义如下:

<field name="move_lines" string="Stock Move" context="{'address_in_id': partner_id, 'form_view_ref':'stock.view_move_picking_form', 'tree_view_ref':'stock.view_move_picking_tree', 'picking_type': 'internal'}" options='{"reload_on_button": true}'/>

你可以在上下文中看到我们需要tree_view_ref的价值。

因此,如果要将字段添加到树视图中,请尝试以下操作:

<record id="view_move_tree_inherit" model="ir.ui.view">
        <field name="name"> view.move.tree.inherit</field>
        <field name="model">stock.move</field>
        <field name="inherit_id" ref="stock.view_move_picking_tree"/>
        <field name="arch" type="xml">
            <xpath expr="//field[@name='state']" position="after">
                <field name="add_new_field"/>
            </xpath>
        </field>
    </record>