如何在销售订单行中添加字段?

时间:2016-09-07 11:34:44

标签: xml odoo-8

我想将“发货”字段添加到销售订单行作为下拉列表(many2one字段)。

我的xml文件 ship_view.xml

<record model="ir.ui.view" id="ship_orderline">
    <field name="model">sale.order.line</field>
    <field name="name">sale.form</field>
    <field name="inherit_id" ref="sale.view_order_form"/>
    <field name="arch" type="xml">   
        <xpath expr="//field[@name='order_line']/tree/field[@name='product_uom_qty']" position="before">
            <field name="ship"/>
        </xpath>
    </field>
</record>

1 个答案:

答案 0 :(得分:0)

尝试以下代码。检查视图中的模型应为sale.order

Python代码

from openerp import models, fields


class CustomSaleOrderLine(models.Model):
    _inherit = 'sale.order.line'

    ship = fields.Char(
        string='Ship',
    )

XML视图

<record model="ir.ui.view" id="ship_orderline">
    <field name="model">sale.order</field>
    <field name="name">sale.order.form</field>
    <field name="inherit_id" ref="sale.view_order_form"/>
    <field name="arch" type="xml">  
        <xpath expr="//field[@name='order_line']/tree//field[@name='product_uom_qty']" position="before">
            <field name="ship"/>
        </xpath>
    </field>
</record>