在odoo中将自定义字段添加到sale.order时出错

时间:2015-02-10 03:23:23

标签: python openerp odoo

我将自定义字段添加到order.sale表单中,但是可以显示错误变量的安装模块字段detail不存在

这是xml代码:

<?xml version="1.0" encoding="utf-8"?>

<openerp>

<data>

   <record model="ir.ui.view" id="detail_field_in_view">

        <field name="name">New Sale Order field detail</field>

        <field name="model">sale.order</field>

        <field name="inherit_id" ref="sale.view_order_form"/>

        <field name="arch" type="xml">

        <xpath expr="//form/sheet/notebook/page/field[@name='order_line']/form/group/group/field[@name='price_unit' ]" position="before">

            <field name="detail" />

        </xpath>

        </field>

   </record>

</data>

</openerp>

这是.py代码:

from openerp.osv import fields, osv

class test_res(osv.osv):

    _inherit = ['sale.order','product.product']

    _columns = {

        'detail': fields.text('Detail'),

    }

1 个答案:

答案 0 :(得分:1)

如果要在Order行中添加任何字段,而不是在sale.order.line对象下定义该字段。因为在sale.order,字段order_linesale.order.line

之间存在一个2关系

尝试使用此代码:

from openerp.osv import fields, osv

class sale_order_line(osv.osv):
    _inherit = 'sale.order.line'

    _columns = {

        'detail': fields.text('Detail'),
    }

这是xml代码:

<record model="ir.ui.view" id="detail_field_in_view">

    <field name="name">New Sale Order field detail</field>

    <field name="model">sale.order</field>

    <field name="inherit_id" ref="sale.view_order_form"/>

    <field name="arch" type="xml">

        <xpath expr="//form/sheet/notebook/page/field[@name='order_line']/form/group/group/field[@name='price_unit' ]" position="before">

            <field name="detail" />

        </xpath>

    </field>

</record>