Skip to Content
Menu
This question has been flagged
4 Replies
5221 Views

ello,

I'm a beginner, but I want to customize myself some odoo module.

First, I want to add a field maned "NISS" in to the employee module.

This field must be located after the field "name"

My code is wrong, but i don't no why :

_manifest_.py

# -*- coding: utf-8 -*-
{
    'name': 'Gestion du personnel ',
    'version': '1.0',
    'category': '',
    'sequence': 5,
    'summary': 'Module gestion personnel pour - modification du module employé existant',
    'description': "Module de gestion du personnel et sous traitants",
    'website': 'https://www.dimdim.be',
    'depends':['base','hr',],
    'data': [
#    
                'views/custom_employees_view.xml',
            ],
    'demo': [
        '',
    ],
    'css': [''],
    'installable': True,
    'application': False,
    'auto_install': False
}

_init_.py

# -*- coding: utf-8 -*-
from . import custom_employees


custom_employees.py

from odoo import models, fields
class custom_info(models.Model):
    _inherit = 'hr.employee'
    NISS = fields.Char(string="NISS : ", required=True)


custom_employees_view.xml       

<?xml version="1.0" encoding="utf-8"?>
    <odoo>
        <record id="viewcustom_employee" model="ir.ui.view">
            <field name="name">viewcustom.employee</field>
            <field name="model">hr.employee</field>
            <field name="inherit_id" ref="hr.view_employee_form"/>
            <field name="arch" type="xml">
                    <field name="name" position="after"/>
                    <field name="NISS"/>
            </field>
                
        </record>
    </odoo>

Error message when installing :


odoo.tools.convert.ParseError: "L'élément '<field name="NISS">' ne peut être localisé dans la vue parente

Contexte de l'erreur :
Vue `viewcustom.employee`
[view_id: 466, xml_id: n/a, model: hr.employee, parent_id: 418]" while parsing /opt/odoo13/odoo-custom-addons/custom_employees/views/custom_employees_view.xml:2, near
<odoo>
        <record id="viewcustom_employee" model="ir.ui.view">
            <field name="name">viewcustom.employee</field>
            <field name="model">hr.employee</field>
            <field name="inherit_id" ref="hr.view_employee_form"/>
            <field name="arch" type="xml">
                    <data><field name="name" position="after"/>
                    <field name="NISS"/>
            </data></field>
                
        </record>
    </odoo>

Somebody can help me ?

Thanks

Avatar
Discard
Best Answer

I am impressed that you really tried by yourself first before asking a question.

All your code is almost correct except XML. You just had to add your field in between the name field. Just put the following code in your XML:

<field name="name" position="after">
<field name="NISS"/>
</field>

So, your XML will look like this:

<record id="viewcustom_employee" model="ir.ui.view">
<field name="name">viewcustom.employee</field>
<field name="model">hr.employee</field>
<field name="inherit_id" ref="hr.view_employee_form"/>
<field name="arch" type="xml">
<field name="name" position="after">
<field name="NISS"/>
</field>

</field>
</record>



Avatar
Discard
Best Answer

You can also add using xpath like
<xpath expr="//field[@name='name']" position="after">

    <field name="NISS"/>
</xpath>


thats another way of adding fields in inherited view.

Avatar
Discard
Author Best Answer

Thanks !

It works good.
Now i'm trying to developp some more.
Thanks to all


Avatar
Discard
Related Posts Replies Views Activity
4
Aug 23
10801
2
Mar 15
3630
3
Jun 23
1191
1
Jun 23
1285
2
Jun 23
1106