Search code examples
pythoninheritancexpathmoduleodoo

problem with inherit a view - Odoo Module


I want to inherit a view from the module hr.employee I use odoo 13

I tried different xpath and there are 2 problems i saw : - The field "directeur" does not exist - xpath cannot locate parent field

here my code : Site View

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

    <record model="ir.ui.view" id="cinema_site_form">
        <field name="name">Site Form View</field>
        <field name="model">cinema.site</field>
        <field name="arch" type="xml">
            <form string="Site">
                <sheet>
                    <h1>
                        <field name="name" placeholder="Site Name"/>
                    </h1>
                    <notebook>
                        <page string = "Détails">
                        <group>
                            <field name="adresse"/>
                            <field name="site_web"/>
                        </group>
                        </page>
                        <page string="Salles">
                            <field name="salle_ids"/>
                        </page>
                    </notebook>
                </sheet>
            </form>
        </field>
    </record>
    <record id="view_hr_employee_form_inherit" model="ir.ui.view">
            <field name="name">hr.employee.form.inherit</field>
            <field name="model">hr.employee</field>
            <field name="inherit_id" ref="hr.view_employee_form"/>
            <field name="arch" type="xml">
                <xpath expr="//field[@name='name']" position="after">
                    <field name="directeur"/>
                </xpath>
            </field>
    </record>
</odoo>

Site py

from odoo import api, fields, models
from odoo.exceptions import UserError


class Sites(models.Model):
    _name = 'cinema.site'
    name = fields.Char("Site Name")
    salle_ids = fields.One2many("cinema.salle", "site_id", string="Salles")
    adresse = fields.Char()
    site_web = fields.Char()


class hremployee(models.Model):
    _inehrit = 'hr.employee'
    directeur = fields.Char()

my manifest is adapted

'depends': ['base','web','hr'],

Thx for your help and sorry for my english


Solution

  • Your _inherit spelling is wrong. Please use the following code.

    class HrEmployee(models.Model):
        _inherit = 'hr.employee'
    
        directeur = fields.Char()
    

    Hope this worked for you.