Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

1

View definition error for inherited view [Closed]

By
oumaima
on 5/1/13, 7:14 PM 3,008 views

The Question has been closed

by
Sudhir Arya (SA)
on 05/02/2013 09:10:18

Hi everyone,i try to add a field in an inherit view from the feature hr(human ressource) but i have this error:

AttributeError: View definition error for inherited view 'ressources humaines.view_rh_inherit' on model 'hr.employee': Element '<xpath expr="/form/name">' not found in parent view 'hr.view_employee_form'

code of rh.py

from osv import fields,osv

class hr_employe(osv.osv):
_name = 'hr.employee'
_inherit='hr.employee'
_columns = {
  'pren': fields.char('Nom Famille', size=64, required=True),
}

hr_employe()

code of rh_view :

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

<record model="ir.ui.view" id="view_rh_inherit">
    <field name="name">hr.employee.form.inherit</field>
    <field name="model">hr.employee</field>
    <field name="type">form</field>
    <field name="inherit_id" ref="hr.view_employee_form">form</field>
    <field name="arch" type="xml">
        <xpath expr ="/form/name" position="before">
            <field name="pren" colspan="4" />
        </xpath>
    </field>
 </record>

</data>
</openerp>

Please specify OpenERP version.

Sudhir Arya (SA)
on 5/2/13, 1:55 AM

i'm using openerp V7

oumaima
on 5/2/13, 5:17 AM
2

Sudhir Arya (SA)

--Sudhir Arya (SA)--
10150
| 6 8 8
Ahmedabad, India
--Sudhir Arya (SA)--

Working as an OpenERP/Odoo developer and a Team Leader 

Top 5 Odoo contributor On Stackoverflow

LinkedIn

Blog

Stackoverflow

Sudhir Arya (SA)
On 5/2/13, 5:21 AM

As Naresh said your xpath is wrong. As per my suggestion xpath is not required in this case you can direct use field and position.

Try this:

<field name="name" position="before">
    <field name="pren" colspan="4"/>
</field>

This will work for sure.

yes sudhir, that's just another way to inherit a view ! Xpath should be used if the parent view is complex otherwise normal inheritance should work.

Naresh Soni (nch)
on 5/2/13, 5:24 AM

It works but it just replace the first field even if i specify the field goal...

oumaima
on 5/2/13, 6:12 AM

yes, as I said sudhir method will work only for normal inheritance.

Naresh Soni (nch)
on 5/2/13, 7:15 AM
1

Naresh Soni (nch)

--Naresh Soni (nch)--
Tiny ERP Pvt Ltd
http://www.odoo.com
1281
| 2 2 4
India
--Naresh Soni (nch)--

Team Lead, Odoo(Formerly OpenERP) Support & OPW

Naresh Soni (nch)
On 5/2/13, 5:03 AM

Hello Oumaima,

Your xpath syntax seems wrong !
use <xpath expr="/form/field[@name='name of the field in parent view']" position="before">

Thanks,

Hi,it doesn't work but the method of Sudhir works

oumaima
on 5/2/13, 6:12 AM

check the /path that leads to the field/ i.e eg:/form/notebook/page the path should be the full path where your source field resides.

Naresh Soni (nch)
on 5/2/13, 7:14 AM
0
oumaima
On 5/2/13, 8:24 AM

AttributeError: View definition error for inherited view 'rhp.view_rh_inherit' on model 'hr.employee': Element '<xpath expr="/form/field/notebook[@name='work_location']">' not found in parent view 'hr.view_employee_form'

I want to add now a field in the view :

enter code here

rh.py

from osv import fields,osv import time from datetime import datetime from tools.translate import _

class hr_employe(osv.osv):

_name = 'hr.employee'
_inherit='hr.employee'
_columns = {
  'name': fields.char('oum', size=64, required=True),
}

hr_employe()

enter code here

rh_view.xml

<openerp> <data> <record model="ir.ui.view" id="view_rh_inherit"> <field name="name">hr.employee.form.inherit</field> <field name="model">hr.employee</field> <field name="type">form</field> <field name="inherit_id" ref="hr.view_employee_form">form</field> <field name="arch" type="xml"> <xpath expr="/form/field/notebook[@name='work_location']" position="after">
<field name="name" colspan="4"/> </xpath> </field> </record> </data> </openerp>

the code of the inherit view hr.employee.form

enter code here

<record id="view_employee_form" model="ir.ui.view"> <field name="name">hr.employee.form</field> <field name="model">hr.employee</field> <field name="arch" type="xml"> <form string="Employee" version="7.0"> <sheet> <field name="image_medium" widget="image" class="oe_left oe_avatar"/> <notebook> <page string="Public Information"> <group> <group string="Contact Information"> <field name="address_id" on_change="onchange_address_id(address_id)" context="{'show_address': 1}" options="{"always_reload": True, "highlight_first_line": True}"/> <field name="**work_email**" widget="email"/> <field name="work_phone"/> <field name="mobile_phone"/> <field name="work_location"/> </group>

Try this: <xpath expr="/form/field/notebook/page/field[@name='work_location']" position="after"> <field name="name" colspan="4"/> </xpath>

Sudhir Arya (SA)
on 5/2/13, 8:31 AM

Here, you cannot use name field twice in same form view.

Sudhir Arya (SA)
on 5/2/13, 8:32 AM

As I said you don't need xpath for such requirement. You can directly use field and it's position.

Sudhir Arya (SA)
on 5/2/13, 8:34 AM

I changed the field name in the .py file : 'prr': fields.char('oum', size=64, required=True), and in the .xml file i replace the xpath line by : <field name="arch" type="xml">
<field name="work_email" position="before" /> <field name="prr" colspan="4" /> </field> and it still doesn't work,help please

oumaima
on 5/2/13, 8:40 AM

What error you are facing?

Sudhir Arya (SA)
on 5/2/13, 8:43 AM

hi, the error is AttributeError: View definition error for inherited view 'rhp.view_rh_inherit' on model 'hr.employee': Element '<field name="prr" colspan="4">' not found in parent view 'hr.view_employee_form' Ok

oumaima
on 5/2/13, 8:45 AM

The error does not come from this line:? <field name="inherit_id" ref="hr.view_employee_form">form</field>

oumaima
on 5/2/13, 8:50 AM

Your syntax is wrong. Try this: <field name="arch" type="xml"> <field name="work_email" position="before"><field name="prr" colspan="4" /></field></field>

Sudhir Arya (SA)
on 5/2/13, 8:52 AM

thank youuu a loot it work's,now i can modified my module

oumaima
on 5/2/13, 9:00 AM

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 5/1/13, 7:14 PM
Seen: 3008 times
Last updated: 7/10/15, 3:47 AM