user3751838
user3751838

Reputation: 1

Error while adding custom field into sale.order in odoo

I will add a custom field into order.sale form, but install module that can show the error variable Field detail does not exist

Here is xml code:

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

Here is .py code:

from openerp.osv import fields, osv

class test_res(osv.osv):

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

    _columns = {

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

    }

Upvotes: 0

Views: 1630

Answers (1)

Bhavesh Odedra
Bhavesh Odedra

Reputation: 11141

If you want to add any field in Order line than you need to define that field under sale.order.line object. Because in sale.order, field order_line has one2many relationship with sale.order.line

try with this code:

from openerp.osv import fields, osv

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

    _columns = {

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

Here is xml code:

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

Upvotes: 1

Related Questions