Skip to Content
Menu
This question has been flagged
2 Replies
12678 Views

 someone can help me with _inherit in odoo 12

in my .py i have

from odoo import fields,api,models



class Employes(models.Model):

    _name="employes"

    _inherit = 'hr.employee'

    categorie= fields.Char(string = "Categorie")





in my .xml file i have

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

<odoo>

<!--Definition de la vue-->

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

    <field name="name">hr.employee.form</field>

    <field name="model">hr.employee</field>

    <field name="type">tree</field>

    <field name="inherit_id" ref='hr.view_employee_tree'/>

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

        <xpath expr = "//field[@name='department_id']" position = "before">

        <group>

        <field name = "categorie"/>

        </group>>

        </xpath>

    </field>

</record>

</odoo>



when i compile this error appear

Le champ `categorie` n'existe pas

Contexte de l'erreur :
Vue `hr.employee.form`
[view_id: 507, xml_id: n/a, model: hr.employee, parent_id: 410]
None" while parsing /root/odoo/addons/Gestion_RH/views/vue_employe.xml:4, near
<record model="ir.ui.view" id="hr_employee_form">
    <field name="name">hr.employee.form</field>
    <field name="model">hr.employee</field>
    <field name="type">tree</field>
    <field name="inherit_id" ref="hr.view_employee_tree"/>
    <field name="arch" type="xml">
        <xpath expr="//field[@name='department_id']" position="before">
        <group>
        <field name="categorie"/>
        </group>&gt;
        </xpath>
    </field>
</record>


Avatar
Discard
Best Answer

Hi,

Update the python file like this, no need to give the _name, so copy the below code and see.

class Employes(models.Model):
_inherit = 'hr.employee'

categorie = fields.Char(string="Categorie")

UPDT: In the XML,


<record model="ir.ui.view" id="hr_employee_form">
<field name="name">hr.employee.form</field>
<field name="model">hr.employee</field>
<field name="type">tree</field>
<field name="inherit_id" ref="hr.view_employee_tree"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='department_id']" position="before">
<group>
<field name="categorie"/>
</group>
</xpath>
</field>
</record>

Thanks

Avatar
Discard
Author Best Answer

thanks for your answer but when i do it another error appear

File "/root/odoo/odoo/addons/base/models/ir_ui_view.py", line 360, in _check_xml
    raise ValidationError(_('Invalid view %s definition in %s') % (view.name, view.arch_fs))
odoo.tools.convert.ParseError: "Invalid view hr.employee.form definition in Gestion_RH/views/vue_employe.xml
None" while parsing /root/odoo/addons/Gestion_RH/views/vue_employe.xml:4, near
<record model="ir.ui.view" id="hr_employee_form">
    <field name="name">hr.employee.form</field>
    <field name="model">hr.employee</field>
    <field name="type">tree</field>
    <field name="inherit_id" ref="hr.view_employee_tree"/>
    <field name="arch" type="xml">
        <xpath expr="//field[@name='department_id']" position="before">
        <group>
        <field name="categorie"/>
        </group>&gt;
        </xpath>
    </field>
</record>

Avatar
Discard

see the updated answer, remove &gt; coming after the </group>

Author

ok after remove &gt it's success but my field "Categorie" don't appear in the view of employe.

my security file content this

id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink

access_hr_employee,access.hr_employee,model_hr_employee,base.group_user,1,1,1,0

and my file .xml become

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

<odoo>

<!--Definition de la vue-->

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

<field name="name">hr.employee.form</field>

<field name="model">hr.employee</field>

<field name="type">tree</field>

<field name="inherit_id" ref='hr.view_employee_tree'/>

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

<xpath expr = "//field[@name='department_id']" position = "before">

<field name = "categorie"/>

</xpath>

</field>

</record>

</odoo>