hela hela - 3 months ago 28
Python Question

Error while trying to add column in inherited view Odoo

I'm trying to add a column in a existing view , I'm new with odoo , this is my xml code

<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record model="ir.ui.view" id="mrp_form_view">
<field name="name"> mrp.fleuret.form</field>
<field name="model"> mrp.bom</field>
<field name="type">form</field>
<field name="inherit_id" ref="mrp.mrp_bom_form_view" />

<field name="arch" type="xml">
<xpath expr="page[@string='Components']/field[@name='bom_line_ids']/tree[@string='Components'/field[@name='date_stop']" position="after">
<field name="unit_price"/>
</xpath>
</field>
</record>
</data>
</openerp>


and this is my python code :

from openerp.osv import osv, fields

class fleuret(osv.Model):

_inherit = "mrp.bom.line"
_columns = {
'unit_price' : fields.float('unit price'),
}


parent form view

Answer

You just need to update your xml code, issue was there in xpath.

You should try following,

<record model="ir.ui.view" id="mrp_form_view">
    <field name="name"> mrp.fleuret.form</field>
    <field name="model"> mrp.bom</field>
    <field name="type">form</field>
    <field name="inherit_id" ref="mrp.mrp_bom_form_view" />
    <field name="arch" type="xml">
        <xpath expr="//field[@name='bom_line_ids']/tree/field[@name='date_stop']" position="after">
            <field  name="unit_price"/>
        </xpath> 
    </field>
 </record>

Or you can also write xpath like that,

<xpath expr="//page[@string='Components']/field[@name='bom_line_ids']/tree[@string='Components']/field[@name='date_stop']" position="after">
Comments