Skip to Content
Menu
This question has been flagged
1 Reply
2928 Views

created model to inherit res.users and added 'supervisor' field and i can see this field in pgAdmin and also in Settings ->Technical -> Fields

i am trying to add 'supervisor' in user's form, please check below 2 screenshots, what am i doing wrong here? the inherited Users form not showing my custom field 'supervisor' after partner_id ( Related Partner in below form ). note i have added view file name in manifest file, also added 'base' in manifest file, then start server with upgrade the module using -u custom_module -d db_17 



plesae help.

regards

Avatar
Discard
Best Answer

The field PARTNER_ID appears twice in the View you are inheriting.

Your field is being added after the FIRST occurrence, which will be hidden unless the User is archived and the Contact is not:

You want to add it after the SECOND occurrence.

See https://www.odoo.com/forum/help-1/select-multiple-elements-with-xpath-116090


You may be misunderstanding the Odoo data model - a User is a set of credentials and access rights - it is not an Employee.

The Employee App already has a Manager:




Avatar
Discard
Author

thank you @Ray for reply.
yes, Manager is exist but the requirement is what i am trying to implement.

i have modified code (as per what i understand from link provided) but it is still not showing on user's form view, please check what i am missing or doing wrong here.

<?xml version="1.0" encoding="utf-8"?>
<odoo>
<!-- Define a new view for inherited model -->
<record id="view_custom_res_user_form" model="ir.ui.view">
<field name="name">custom.res.users.form</field>
<field name="model">res.users</field>
<field name="inherit_id" ref="base.view_users_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='partner_id'][1]" position="after">
<xpath expr="//field[@name='partner_id'][2]" position="after">
<field name="supervisor"/>
</xpath>
</xpath>
</field>
</record>
</odoo>

regards

Author

The error in Odoo.log file as below:

Error while parsing or validating view:

Element '<xpath expr="//field[@name=&#39;partner_id&#39;][2]">' cannot be located in parent view

View error context:
{'file': 'd:\\program files\\odoo '
'17.0.20240101\\server\\odoo\\custom_addons\\brb_customizations\\views\\res_users_view.xml',
'line': 2,
'name': 'custom.res.users.form',
'view': ir.ui.view(1338,),
'view.model': 'res.users',
'view.parent': ir.ui.view(162,),
'xmlid': 'view_custom_res_user_form'}

.

Author

sorry @Ray, by mistake i posted above error in Odoo.log please ignore it, it was because of before my posted code in your reply.

Author

my first Comment to your Answer is valid, the 2nd one in which i posted error in Odoo.log is not.
waiting for your reply on my first Comment.
regards

In your first comment, you have an xpath inside an xpath and this is not supported.

If you wish to place your field after the second partner_id just reference the second partner_id - you don't need to reference the first at all

Author

@Ray
i have check with code below, its not even start Odoo Server and showing errors in odoo.log file as below:
-------
Element '<xpath expr="//field[@name=&#39;partner_id&#39;][2]">' cannot be located in parent view

View error context:
{'file': 'd:\\program files\\odoo '
'17.0.20240101\\server\\odoo\\custom_addons\\brb_customizations\\views\\res_users_view.xml',
'line': 3,
'name': 'custom.res.users.form',
'view': ir.ui.view(1338,),
'view.model': 'res.users',
'view.parent': ir.ui.view(162,),
'xmlid': 'view_custom_res_user_form'}
--------

modified code as per your instruction:

<?xml version="1.0" encoding="utf-8"?>
<odoo>
<!-- Define a new view for inherited model -->
<record id="view_custom_res_user_form" model="ir.ui.view">
<field name="name">custom.res.users.form</field>
<field name="model">res.users</field>
<field name="inherit_id" ref="base.view_users_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='partner_id'][2]" position="after">
<field name="supervisor"/>
</xpath>
</field>
</record>
</odoo>

please advice and help.
regards

Related Posts Replies Views Activity
2
Oct 24
1653
2
Jun 24
1068
0
Jan 24
1159
1
Mar 20
2680
12
Dec 18
33776